From 4e07dfef1febe61e710d81a77e2bfd2623f6d594 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Wed, 22 Oct 2014 01:11:34 -0700 Subject: [PATCH] Add benchmark for hash-fetch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calculating ------------------------------------- fetch with no block 66979 i/100ms fetch with a block 138257 i/100ms brackets with an || 145792 i/100ms ------------------------------------------------- fetch with no block 1255521.2 (±5.2%) i/s - 6296026 in 5.028856s fetch with a block 6402972.5 (±8.1%) i/s - 31799110 in 5.002554s brackets with an || 8536511.4 (±8.1%) i/s - 42425472 in 5.005831s --- benchmark/hash-fetch | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 benchmark/hash-fetch diff --git a/benchmark/hash-fetch b/benchmark/hash-fetch new file mode 100644 index 00000000..35708357 --- /dev/null +++ b/benchmark/hash-fetch @@ -0,0 +1,9 @@ +require 'benchmark/ips' + +h = {:bar => 'uco'} + +Benchmark.ips do |x| + x.report('fetch with no block') { h.fetch(:bar, (0..9).to_a) } + x.report('fetch with a block') { h.fetch(:bar) { (0..9).to_a } } + x.report('brackets with an ||') { h[:bar] || (0..9).to_a } +end