Skip to content

Instantly share code, notes, and snippets.

@akshay-vishnoi
Created November 29, 2013 13:34
Show Gist options
  • Save akshay-vishnoi/7705772 to your computer and use it in GitHub Desktop.
Save akshay-vishnoi/7705772 to your computer and use it in GitHub Desktop.
Removing &block from method
# ruby 2.0.0-p247
require 'benchmark'
def old_method(&block)
yield
end
def new_method
yield
end
TIMES = 500_000
Benchmark.bmbm do |b|
b.report('old') do
TIMES.times do
old_method { 'abc' }
end
end
b.report('new') do
TIMES.times do
new_method { 'abc' }
end
end
end
Rehearsal ---------------------------------------
old 0.590000 0.020000 0.610000 ( 0.615266)
new 0.160000 0.000000 0.160000 ( 0.159566)
------------------------------ total: 0.770000sec
user system total real
old 0.570000 0.020000 0.590000 ( 0.584801)
new 0.130000 0.000000 0.130000 ( 0.131258)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment