Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rinaldifonseca/3594601 to your computer and use it in GitHub Desktop.
Save rinaldifonseca/3594601 to your computer and use it in GitHub Desktop.
require 'benchmark/ips'
h = { foo: :bar }
Benchmark.ips do |r|
r.report('#[]') { h[:foo] }
r.report('#fetch') { h.fetch(:foo) }
end
Calculating -------------------------------------
#[] 84463 i/100ms
#fetch 58818 i/100ms
-------------------------------------------------
#[] 3004469.2 (±1.6%) i/s - 15034414 in 5.005338s
#fetch 2196062.9 (±0.8%) i/s - 10998966 in 5.008783s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment