Skip to content

Instantly share code, notes, and snippets.

@alexch
Created April 21, 2009 17:04
Show Gist options
  • Save alexch/99250 to your computer and use it in GitHub Desktop.
Save alexch/99250 to your computer and use it in GitHub Desktop.
# 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