Created
June 9, 2015 07:37
-
-
Save donigian/66999e63a471fa624f57 to your computer and use it in GitHub Desktop.
Ruby Benchmark Howto
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 calculation_with_explicit_block_passing(a, b, operation) | |
operation.call(a, b) | |
end | |
def calculation_with_implicit_block_passing(a, b) | |
yield(a, b) | |
end | |
Benchmark.bmbm(10) do |report| | |
report.report("explicit") do | |
addition = lambda { |a, b| a + b } | |
1000.times { calculation_with_explicit_block_passing(5, 5, addition) } | |
end | |
report.report("implicit") do | |
1000.times { calculation_with_implicit_block_passing(5, 5) { |a, b| a + b } } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment