Add benchmark for hash-fetch

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
This commit is contained in:
Parker Moore 2014-10-22 01:11:34 -07:00
parent 0511ece2f5
commit 4e07dfef1f
1 changed files with 9 additions and 0 deletions

9
benchmark/hash-fetch Normal file
View File

@ -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