-
-
Save mattyoho/320355 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'rbench' | |
require 'find' | |
def glob(dir) | |
hash = {} | |
Dir.glob("#{dir}/**/*.rb") do |f| | |
hash[f] = File.mtime(f) rescue next | |
end | |
return hash | |
end | |
def find(dir) | |
hash = {} | |
Find.find(dir) do |f| | |
hash[f] = File.mtime(f) rescue next if /\.rb$/o === f | |
end | |
return hash | |
end | |
path = ARGV.shift or raise "Specify directory" | |
find(path) # file cache | |
glob(path) # file cache | |
RBench.run(100) do | |
report("glob") {glob(path)} | |
report("find") {find(path)} | |
end | |
__END__ | |
# 241 files | |
Results | | |
---------------------- | |
glob 0.661 | | |
find 1.820 | | |
# 1016 files | |
Results | | |
---------------------- | |
glob 2.570 | | |
find 11.108 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment