Skip to content

Instantly share code, notes, and snippets.

@mipearson
Created September 13, 2011 05:20
Show Gist options
  • Save mipearson/1213178 to your computer and use it in GitHub Desktop.
Save mipearson/1213178 to your computer and use it in GitHub Desktop.
File.exist? benchmark of existing / non existing file
ubuntu@localtest:~$ cat stat.rb
require 'benchmark'
puts Benchmark.measure {
1000000.times do
File.exist?(ARGV[0])
end
}
ubuntu@localtest:~$ ls -l foo
ls: cannot access foo: No such file or directory
ubuntu@localtest:~$ ruby stat.rb foo
0.570000 0.310000 0.880000 ( 0.876064)
ubuntu@localtest:~$ ruby stat.rb stat.rb
0.560000 0.390000 0.950000 ( 0.952491)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment