Created
April 21, 2009 17:04
-
-
Save alexch/99250 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
# block: 0.052654 | |
# yield: 0.015362 | |
def with_block(&block) | |
block.call | |
end | |
def with_yield | |
yield | |
end | |
def measure(name) | |
start = Time.now | |
yield | |
finish = Time.now | |
puts "#{name}: #{finish - start}" | |
end | |
measure "block" do | |
sum = 0 | |
10000.times do | |
with_block do | |
sum = sum + 1 | |
end | |
end | |
end | |
measure "yield" do | |
sum = 0 | |
10000.times do | |
with_yield do | |
sum = sum + 1 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment