Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
19 lines (14 sloc) 275 Bytes
require "benchmark/ips"
HASH = Hash[*("a".."zzz").to_a.shuffle]
KEY = "zz"
def key_fast
HASH.key? KEY
end
def key_slow
HASH.keys.include? KEY
end
Benchmark.ips do |x|
x.report("Hash#keys.include?") { key_slow }
x.report("Hash#key?") { key_fast }
x.compare!
end
You can’t perform that action at this time.