Create a gist now

Instantly share code, notes, and snippets.

@ko1 /medama.rb
Created Oct 23, 2017

What would you like to do?
def iter_yield
yield
end
def iter_pass &b
iter_yield(&b)
end
def iter_yield_bp &b
yield
end
def iter_call &b
b.call
end
require 'benchmark'
Benchmark.bm(10){|x|
x.report("yield"){
10_000_000.times{ # 10M
iter_yield{}
}
}
x.report("yield_pass"){
10_000_000.times{ # 10M
iter_pass{}
}
}
x.report("yield_bp"){
10_000_000.times{ # 10M
iter_yield_bp{}
}
}
x.report("call"){
10_000_000.times{ # 10M
iter_call{}
}
}
}
__END__
trunk (r60312)
user system total real
yield 0.572854 0.000000 0.572854 ( 0.572519)
yield_pass 2.850774 0.000000 2.850774 ( 2.850354)
yield_bp 2.665396 0.000000 2.665396 ( 2.663879)
call 3.043068 0.000000 3.043068 ( 3.041972)
modified
user system total real
yield 0.640713 0.000000 0.640713 ( 0.640155)
yield_pass 0.925146 0.000000 0.925146 ( 0.924564)
yield_bp 0.723170 0.000000 0.723170 ( 0.723373)
call 2.812172 0.000004 2.812176 ( 2.814317)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment