Skip to content

Instantly share code, notes, and snippets.

@mattyoho
Forked from maiha/glob-vs-find.rb
Created March 3, 2010 05:27
Show Gist options
  • Save mattyoho/320355 to your computer and use it in GitHub Desktop.
Save mattyoho/320355 to your computer and use it in GitHub Desktop.
#!/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