Skip to content

Instantly share code, notes, and snippets.

@Shinpeim
Created September 4, 2014 17:13
Show Gist options
  • Save Shinpeim/90235247dc05947bd7bf to your computer and use it in GitHub Desktop.
Save Shinpeim/90235247dc05947bd7bf to your computer and use it in GitHub Desktop.
require 'benchmark'
n = 500000
def lm
lambda{1}.call
end
def bg
begin
1
end
end
Benchmark.bm(7, ">total:", ">avg:") do |x|
x.report("lambda:") do
n.times {lm}
end
x.report("begin:") do
n.times {bg}
end
end
user system total real
lambda: 0.440000 0.000000 0.440000 ( 0.443400)
begin: 0.040000 0.000000 0.040000 ( 0.040375)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment