Revision 687785a00d665f3a134b28fcd2b3d0260e27c510 authored by Parker Moore on 03 August 2020, 20:29:36 UTC, committed by Parker Moore on 03 August 2020, 20:29:36 UTC
1 parent ac7b264
Raw File
hash-fetch
#!/usr/bin/env ruby
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
back to top