-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
Improve performance of multipliedBy one if value is one #24
Conversation
Thanks, looking good! Could you please apply the same optimization to Also, it looks like |
src/BigDecimal.php
Outdated
|
||
if ($that->value === '0' || $this->value === '0') { | ||
return new BigDecimal('0', $this->scale + $that->scale); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about this one: the optimizations above are really to return one of the objects without modification whenever possible, but for the other micro-optimizations, they're already handled by the calculator if needed.
I don't think this extra check brings much value.
Thanks for your work here! This is overall very good, I'm just a bit torn regarding everything that doesn't return The aim of these optimizations is mainly to avoid creating a new object when this is not necessary. From this perspective, returning However, for everything else, like returning In other words, out of your 9 additions:
What's your take on this? |
No feedback here? |
Perfectly makes sense to me @BenMorel, from my perspective -- taking always balance between code complexity&readability and speed. I would take first 4 as these are only one which any possible measurable speed difference. |
@tomtomsen I guess we'll just keep the 4x You can keep all added tests, even if some of some were added to cover the other use cases. They don't hurt. |
@BenMorel Yes, I will update the pull request. |
LGTM! Don't worry, I'm not sure whether your other optimizations are "over the top", it's just hard to benchmark whether they're relevant or not, and whether they justify extra code complexity that also affects readability. For now your 4 new tests are a nice addition. Thank you. |
Released as 0.8.9. |
Currently there is only a check if
$that->value
is one.With this patch
$this->value
will be checked too.