Skip to content

Instantly share code, notes, and snippets.

@lest
Created November 10, 2011 08:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lest/1354411 to your computer and use it in GitHub Desktop.
Save lest/1354411 to your computer and use it in GitHub Desktop.
require 'benchmark'
def method1(&block)
true if block
end
def method2(&block)
true if block_given?
end
n = 10_000_000
Benchmark.bm do |x|
x.report { n.times { method1 {} } }
x.report { n.times { method2 {} } }
end
# user system total real
# 4.780000 0.020000 4.800000 ( 4.792239)
# 5.260000 0.000000 5.260000 ( 5.260888)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment