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
We need to check for redefinition of initialize_dup and
initialize_copy methods in Hash for this to be correct.
Unfortunately for people optimizing Ruby, corner-case
redefinition checks are probably necessary :<
Also, I wonder if we can improve rb_funcall to better support
inline caching. rb_funcall API is also bad since it cannot use
inline cache for method lookup. Maybe a better C API can be
introduced for faster function calls from C.
Note: I checked commit c5d74afdb4cfea2a4c9ff432d9da82f0649a1e67
by having a "fetch = +refs/pull/:refs/remotes/ruby/pull/"
line in a "remote" section of my .git/config. I did not
use any proprietary API or JavaScript to view your changes.
We need to check for redefinition of initialize_dup and
initialize_copy methods in Hash for this to be correct.
Unfortunately for people optimizing Ruby, corner-case
redefinition checks are probably necessary :<
Also, I wonder if we can improve rb_funcall to better support
inline caching. rb_funcall API is also bad since it cannot use
inline cache for method lookup. Maybe a better C API can be
introduced for faster function calls from C.
Note: I checked commit c5d74afdb4cfea2a4c9ff432d9da82f0649a1e67
by having a "fetch = +refs/pull/:refs/remotes/ruby/pull/"
line in a "remote" section of my .git/config. I did not
use any proprietary API or JavaScript to view your changes.
hash.c (rb_hash_merge): use rb_hash_dup() instead of rb_obj_dup() to duplicate
Hash object. rb_hash_dup() is faster duplicating function for Hash object
which got rid of Hash#initialize_dup method calling.