https://github.com/jekyll/jekyll
Raw File
Tip revision: 6e208e89e68285e1f208e1bf54bd6dd9a15f7d02 authored by Parker Moore on 18 April 2016, 21:28:21 UTC
Release :gem: 3.1.3
Tip revision: 6e208e8
hash-fetch
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