Created
July 26, 2011 14:21
-
-
Save radiospiel/1106870 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
$count = 1000000 | |
def bench0(&block) | |
r = Time.now | |
$count.times do end | |
Time.now - r | |
end | |
def bench1(&block) | |
r = Time.now | |
$count.times(&block) | |
Time.now - r | |
end | |
def bench2 | |
r = Time.now | |
$count.times do | |
yield | |
end | |
Time.now - r | |
end | |
def bench3(&block) | |
r = Time.now | |
$count.times do | |
block.call | |
end | |
Time.now - r | |
end | |
def bench4(&block) | |
r = Time.now | |
$count.times do | |
yield | |
end | |
Time.now - r | |
end | |
puts [ bench0 { 1 }, bench1 { 1 }, bench2 { 1 }, bench3 { 1 }, bench4 { 1 } ].inspect | |
# => [0.060988, 0.121777, 0.49548, 1.156454, 0.48538] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment