Skip to content

Instantly share code, notes, and snippets.

@luislavena
Created October 21, 2008 22:34
Show Gist options
  • Save luislavena/18458 to your computer and use it in GitHub Desktop.
Save luislavena/18458 to your computer and use it in GitHub Desktop.
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
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