Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

22 lines (17 sloc) 286 Bytes
require 'benchmark/ips'
ENUM = (1..100)
def slow
ENUM.inject({}) do |h, e|
h.merge(e => e)
end
end
def fast
ENUM.inject({}) do |h, e|
h.merge!(e => e)
end
end
Benchmark.ips do |x|
x.report('Hash#merge') { slow }
x.report('Hash#merge!') { fast }
x.compare!
end
You can’t perform that action at this time.