This project is archived and is in readonly mode.
Hash#symbolize_keys! performance
-
Lourens Naudé
Updated (http://gist.github.com/297772) to handle failures in the following test cases :
- test_symbolize_keys_preserves_keys_that_cant_be_symbolized
- test_symbolize_keys_preserves_fixnum_keys
methodmissing:~ lourens$ ruby hash_bench.rb
Rehearsal -----------------------------------------------------------------------
Hash#orig_symbolize_keys! , nil key 3.500000 0.160000 3.660000 ( 3.686203)
Hash#symbolize_keys! , nil key 0.510000 0.000000 0.510000 ( 0.506390)
Hash#orig_symbolize_keys! 2.000000 0.090000 2.090000 ( 2.096217)
Hash#symbolize_keys! 0.470000 0.000000 0.470000 ( 0.468481)
-------------------------------------------------------------- total: 6.730000secuser system total realHash#orig_symbolize_keys! , nil key 3.520000 0.160000 3.680000 ( 3.753897)
Hash#symbolize_keys! , nil key 0.510000 0.000000 0.510000 ( 0.513103)
Hash#orig_symbolize_keys! 2.020000 0.090000 2.110000 ( 2.115938)
Hash#symbolize_keys! 0.470000 0.000000 0.470000 ( 0.481901) -
Repository
- State changed from new to committed
(from [2060977b767061a42eb8db2d5c3a30d205a94123]) Hash#symbolize_keys(!) optimizations
[#3891 Hash#symbolize_keys! performance state:committed]
Signed-off-by: Jeremy Kemper jeremy@bitsweat.net
http://github.com/rails/rails/commit/2060977b767061a42eb8db2d5c3a30... -
tribalvibes
Could you please show the data that generates those dubious benchmarks ?
For the (typical?) case where the keys are all strings to be symbolized, and not Fixnums, the original is about 25% faster for my tests (which do not factor out the overhead of duplicating the hash for each iteration of the destructive test.) -
Lourens Naudé
Hey,
Thanks for spotting this and apologies for the oversight.
I updated the gist in the original post ( http://gist.github.com/297755 ) with string hash cases and your spot on.
I'll ping Jeremy to revert in favor of the common case.
- Lourens
-
Repository
- State changed from committed to open
(from [e30363617cea5b51de2bb2e535c70092554514d0]) Revert "Hash#symbolize_keys(!) optimizations"
Was slower in common case.
[#3891 Hash#symbolize_keys! performance state:open]
This reverts commit 2060977b767061a42eb8db2d5c3a30d205a94123.
http://github.com/rails/rails/commit/e30363617cea5b51de2bb2e535c700... -
Yehuda Katz (wycats)
- State changed from open to invalid
