Add benchmark for yield vs proc.call

Calculating -------------------------------------
               yield     70018 i/100ms
          block.call     42809 i/100ms
-------------------------------------------------
               yield  1099624.2 (±7.3%) i/s -    5531422 in   5.056107s
          block.call   604006.1 (±7.1%) i/s -    3039439 in   5.058794s
This commit is contained in:
Parker Moore 2014-10-22 01:18:09 -07:00
parent 7e37892bbd
commit 7c05312d5c
1 changed files with 14 additions and 0 deletions

View File

@ -0,0 +1,14 @@
require 'benchmark/ips'
def fast
yield
end
def slow(&block)
block.call
end
Benchmark.ips do |x|
x.report('yield') { fast { (0..9).to_a } }
x.report('block.call') { slow { (0..9).to_a } }
end