New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Hash#merge performance #1533

Closed
wants to merge 1 commit into
base: trunk
from

Conversation

2 participants
@Watson1978
Contributor

Watson1978 commented Mar 7, 2017

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

https://bugs.ruby-lang.org/issues/13343

Improve Hash#merge performance
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
@hsbt

hsbt approved these changes Mar 8, 2017

@hsbt hsbt requested a review from nobu Mar 8, 2017

@hsbt hsbt closed this in 9cd66d7 May 20, 2017

@Watson1978 Watson1978 deleted the Watson1978:hash_merge branch Oct 14, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment