From 5f943ce1c2aa8a6a7764d04978ac1b45d5baf9f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Bu=C5=82at?= Date: Mon, 25 Jan 2016 19:26:57 +0100 Subject: [PATCH] Remove overhead of surrounding block from length-vs-size-vs-count benchmark. See #96 for detailed explanation --- code/array/length-vs-size-vs-count.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/array/length-vs-size-vs-count.rb b/code/array/length-vs-size-vs-count.rb index 6b7ff24..d461840 100644 --- a/code/array/length-vs-size-vs-count.rb +++ b/code/array/length-vs-size-vs-count.rb @@ -1,10 +1,10 @@ require 'benchmark/ips' -ARRAY = [*1..100] +$array = [*1..100] Benchmark.ips do |x| - x.report("Array#length") { ARRAY.length } - x.report("Array#size") { ARRAY.size } - x.report("Array#count") { ARRAY.count } + x.report("Array#length", "$array.length;" * 1_000) + x.report("Array#size", "$array.size;" * 1_000) + x.report("Array#count", "$array.count;" * 1_000) x.compare! end