mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
st.c: use power-of-two sizes to avoid slow modulo ops
* st.c (hash_pos): use bitwise AND to avoid slow modulo op (new_size): power-of-two sizes for hash_pos change (st_numhash): adjust for common keys due to lack of prime modulo [Feature #9425] * hash.c (rb_any_hash): right shift for symbols * benchmark/bm_hash_aref_miss.rb: added to show improvement * benchmark/bm_hash_aref_sym_long.rb: ditto * benchmark/bm_hash_aref_str.rb: ditto * benchmark/bm_hash_aref_sym.rb: ditto * benchmark/bm_hash_ident_num.rb: added to prevent regression * benchmark/bm_hash_ident_obj.rb: ditto * benchmark/bm_hash_ident_str.rb: ditto * benchmark/bm_hash_ident_sym.rb: ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
14c9cf885c
commit
ef59670a44
12 changed files with 77 additions and 57 deletions
4
benchmark/bm_hash_aref_str.rb
Normal file
4
benchmark/bm_hash_aref_str.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
h = {}
|
||||
strs = ('a'..'z').to_a.map!(&:freeze)
|
||||
strs.each { |s| h[s] = s }
|
||||
200_000.times { strs.each { |s| h[s] } }
|
Loading…
Add table
Add a link
Reference in a new issue