https://github.com/jekyll/jekyll
Raw File
Tip revision: 053acd31ac69f915d2e5035dac8a6c6e71ad413c authored by olivia on 25 January 2018, 18:34:49 UTC
Release :gem: 3.7.2
Tip revision: 053acd3
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