Project

General

Profile

Actions

Bug #13343

closed

Improve Hash#merge performance

Added by watson1978 (Shizuo Fujita) about 7 years ago. Updated almost 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-dev:50026]

Description

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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0