From 7c05312d5c9676837730ad7db834e14202bbd72d Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 22 Oct 2014 01:18:09 -0700 Subject: [PATCH] Add benchmark for yield vs proc.call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- benchmark/proc-call-vs-yield | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 benchmark/proc-call-vs-yield diff --git a/benchmark/proc-call-vs-yield b/benchmark/proc-call-vs-yield new file mode 100644 index 00000000..3d55979b --- /dev/null +++ b/benchmark/proc-call-vs-yield @@ -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