This project is archived and is in readonly mode.
faster Hash#except
-
Jeremy Kemper
- State changed from new to open
- Assigned user set to Jeremy Kemper
It already uses Set#include?, not Array#include?, so the benchmark is not equivalent.
Could you base a patch off the recent change made to Hash#slice?
-
Grant Hollingworth
Okay, updated benchmarks:
except: small hash, 100 000 times
user system total real
except_reject 1.250000 0.010000 1.260000 ( 1.318881)
except_each 0.440000 0.000000 0.440000 ( 0.454850)
except: small hash, 100 000 times
user system total real
except_reject! 1.310000 0.020000 1.330000 ( 1.358561)
except_each! 0.150000 0.000000 0.150000 ( 0.155681)
big hash, 1000 times
user system total real
except_reject 6.550000 0.050000 6.600000 ( 6.696907)
except_each 1.720000 0.020000 1.740000 ( 1.780731)
big hash, 1000 times
user system total real
except_reject! 8.710000 0.100000 8.810000 ( 9.683930)
except_each! 0.080000 0.000000 0.080000 ( 0.105305)
I changed the keys from a Set to an Array, like in Hash#slice. Is that what you meant?
-
Repository
- State changed from open to resolved
(from [a797375c99efc88ee1438925cdc016305c66166c]) Performance: speed up Hash#except. [#382 state:resolved]
-
Repository
(from [634e462a0b70ddae2f21dbddddd07e7b340bb69c]) Performance: speed up Hash#except. [#382 state:resolved]
-
Mislav
- Tag set to activesupport, core_ext, patch, tested
This performance optimization breaks because it's using "clone" instead of "dup".
Consider these scenarios which are valid, but which both fail now:
obj1.freeze obj2 = obj1.except(...) # Mocha expectations obj1.expects(:delete).never obj2 = obj1.except(...)Using "dup" in place of "clone" solves both problems. Patch attached
