jekyll/benchmark/hash-fetch

11 lines
295 B
Ruby
Executable File

#!/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