Skip to content

Instantly share code, notes, and snippets.

@radiospiel
Created July 26, 2011 14:21
Show Gist options
  • Save radiospiel/1106870 to your computer and use it in GitHub Desktop.
Save radiospiel/1106870 to your computer and use it in GitHub Desktop.
$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