Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
2 contributors

Users who have contributed to this file

@JuanitoFatas @obrok
12 lines (9 sloc) 329 Bytes
require "benchmark/ips"
HASH = { writing: :fast_ruby }
DEFAULT = "fast ruby"
Benchmark.ips do |x|
x.report("Hash#fetch + const") { HASH.fetch(:writing, DEFAULT) }
x.report("Hash#fetch + block") { HASH.fetch(:writing) { "fast ruby" } }
x.report("Hash#fetch + arg") { HASH.fetch(:writing, "fast ruby") }
x.compare!
end
You can’t perform that action at this time.