From: watson1978@... Date: 2017-03-21T00:49:36+00:00 Subject: [ruby-dev:50026] [Ruby trunk Bug#13343] Improve Hash#merge performance Issue #13343 has been reported by watson1978 (Shizuo Fujita). ---------------------------------------- Bug #13343: Improve Hash#merge performance https://bugs.ruby-lang.org/issues/13343 * Author: watson1978 (Shizuo Fujita) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- Hash#merge will be faster around 60%. ### Before ~~~ user system total real Hash#merge 0.160000 0.020000 0.180000 ( 0.182357) ~~~ ### After ~~~ user system total real Hash#merge 0.110000 0.010000 0.120000 ( 0.114404) ~~~ ### Test code ~~~ require 'benchmark' Benchmark.bmbm do |x| hash1 = {} 100.times { |i| hash1[i.to_s] = i } hash2 = {} 100.times { |i| hash2[(i*2).to_s] = i*2 } x.report "Hash#merge" do 10000.times do hash1.merge(hash2) end end end ~~~ ### Patch The patch is in https://github.com/ruby/ruby/pull/1533 -- https://bugs.ruby-lang.org/