-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hash#fetch with second argument is slower than Hash#fetch with block is not FAIR #117
Comments
Have to agree. Here's some output from ruby 2.3.4p301 which has the block format slower on my machine:
|
The same for me using ruby-2.4.4p296
|
Using benchmark-ips (2.0+) as required.
|
|
Hi! First of all thanks for the nice gem! You are doing great work, making thousand of ruby programs run faster!
Now.. the issue)
Offense
Hash#fetch with second argument is slower than Hash#fetch with block
is not fair.You have this benchamrk: https://github.com/JuanitoFatas/fast-ruby/blob/master/code/hash/fetch-vs-fetch-with-block.rb
But it's assuming that key is always present. What is not really? Otherwise why one passes default value?
Here is my benchmark with
hit
andmiss
cases:Here is the output (ruby 2.1.5p273):
You see that
with 2nd arg (hit)
andwith 2nd arg (hit)
is almost the same, but diff betweenwith 2nd arg (miss)
andwith block (miss)
is quite big.So, IMHO, this offense is not fair and it should be removed.
Thanks!
The text was updated successfully, but these errors were encountered: