-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Correcting Performance/BigDecimalWithNumericArgument
offences leads to slower code
#454
Comments
On my machine the difference is even more stark, with 2.25 worse performance. This actually seems to rise when the number is higher:
Somewhere before 2_000_000_000_000 it inverts, then the integer is 2.3x slower. There's some integer limit there I can't be bothered to find out right now. It might be platform-dependant. |
For me it inverts between So perhaps the cop should be made aware of the limit |
Yeah, right. I totally missed the PR title. Seems like this was released in 3.1.0 from December 2021. RuboCop now has a |
Hoping it's appropriate to offer an opinion here, since Ruby 3.0 is EOL, I'd suggest the best fix here is making the Cop aware of the inversion point, and simply dropping support for 3.0 and below -- either by just stating this in the Docs for this Cop or explicitly disabling it for EOL Ruby versions. |
Yep, I've opened #454 to resolve this issue. |
…_big_decimal_with_numeric_argument [Fix #454] Fix false positives for `Performance/BigDecimalWithNumericArgument`
Performance/BigDecimalWithNumericArgument
suggests thatBigDecimal(2000)
is more performant asBigDecimal("2000")
but that is not the case for recent versions of Ruby/BigDecimal:Gives for me (using Ruby 3.3.3 and BigDecimal 3.1.8):
Having dug a little bit through various Ruby/BigDecimal versions, I think the improvement was introduced in BigDecimal 3.1.0 (which was first included in Ruby 3.1.0), I suspect this PR led to the performance improvement ruby/bigdecimal#178
Expected behavior
There should be no offence for the faster code
BigDecimal(2000)
Actual behavior
There was an offence.
Steps to reproduce the problem
Run rubocop-performance against a file containing
BigDecimal(2000)
RuboCop version
The text was updated successfully, but these errors were encountered: