Open kewlar opened 5 years ago
This is faster than slice
on my machine and returns the same as values_at
:
KEYS.map{ |key| HASH[key] }
@Arcovion, cool! Will add it to the benchmark, too. Thanks!
Added more ways of slicing Hash values, and organized them into three separate cases:
Hash#values_at
);Hash#values_at
);Hash#slice#values
).Thoughts?
@kewlar I see the value in adding code/hash/values_at-vs-map.rb
because it is quite straightforward and natural. But I don't see the value in adding the other benchmarks. The other examples are doing too many things and it is hard to tell which part makes one slower than the other.
I'm happy to add code/hash/values_at-vs-map.rb if you submit just that in this PR or another PR.
@etagwerker, thanks for the feedback!
You're right, the other benchmarks are really just edge cases, and don't contribute much. And Hash#values_at
is the best performing in them anyway.
I've removed the redundant benchmarks. How does it look now?
DO NOT MERGE YET.
Just noticed that
#values_at
and#slice#values
return different results when Hash members are missing 🤦♂️Will update the code and the benchmark, and see if it's still worth merging.