Created
October 21, 2008 22:34
-
-
Save luislavena/18458 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
require 'benchmark' | |
def where(app) | |
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| | |
return File.join(path, app) if File.exist?(File.join(path, app)) && File.executable?(File.join(path, app)) | |
end | |
end | |
n = 1_000 | |
Benchmark.bmbm do |b| | |
b.report('system call') { for i in 1..n; `which ruby`; end } | |
b.report('pure-ruby') { for i in 1..n; where('ruby'); end } | |
end |
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
Rehearsal ----------------------------------------------- | |
system call 0.040000 0.090000 1.170000 ( 1.170017) | |
pure-ruby 0.000000 0.020000 0.020000 ( 0.020001) | |
-------------------------------------- total: 1.190000sec | |
user system total real | |
system call 0.000000 0.090000 0.970000 ( 0.970014) | |
pure-ruby 0.020000 0.010000 0.030000 ( 0.030001) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment