File: hash-fetch

package info (click to toggle)
jekyll 4.3.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,356 kB
  • sloc: ruby: 16,765; javascript: 1,455; sh: 214; xml: 29; makefile: 9
file content (10 lines) | stat: -rwxr-xr-x 295 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
#!/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