Created
March 10, 2012 18:42
-
-
Save tammersaleh/2012444 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require "benchmark" | |
def speak_with_block(&block) | |
block.call | |
end | |
def speak_with_yield | |
yield | |
end | |
n = 1_000_000 | |
Benchmark.bmbm do |x| | |
x.report("&block") do | |
n.times { speak_with_block { "ook" } } | |
end | |
x.report("yield") do | |
n.times { speak_with_yield { "ook" } } | |
end | |
end | |
# 1.9.2 ~/Desktop $ ./shit.rb | |
# Rehearsal ------------------------------------------ | |
# &block 2.260000 0.020000 2.280000 ( 2.761372) | |
# yield 0.570000 0.000000 0.570000 ( 0.674249) | |
# --------------------------------- total: 2.850000sec | |
# | |
# user system total real | |
# &block 2.300000 0.020000 2.320000 ( 2.492953) | |
# yield 0.590000 0.000000 0.590000 ( 0.659533) | |
# 1.9.3 ~/Desktop $ ./shit.rb | |
# Rehearsal ------------------------------------------ | |
# &block 2.450000 0.170000 2.620000 ( 2.648374) | |
# yield 0.420000 0.000000 0.420000 ( 0.435521) | |
# --------------------------------- total: 3.040000sec | |
# | |
# user system total real | |
# &block 2.290000 0.140000 2.430000 ( 3.283690) | |
# yield 0.400000 0.000000 0.400000 ( 0.414590) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment