-
Notifications
You must be signed in to change notification settings - Fork 628
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 Abs() and Round() #240
Conversation
Hi @mwoss! |
Hi @DoubleDi! Could you provide some benchmarks and approximate speed up? |
@mwoss can send you benchmarks after some time but the improvements are using simple math.
This PR was made, when i saw, that over 20% of CPU in our production service, that was doing heavy calculations, was on the Round function. |
I got it, but I was wondering what impact it has on other (typical) use cases. Usually |
For example a typica usecase:
so if you want to optimize you do
Same logic applies to Round (IsNegative() <=> Exp() == -n) Benchmark for passing positive/zero/negative values to Abs()
Results:
|
Thanks for the detailed explanation and benchmarks @DoubleDi! |
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.
Looks good :3
Thanks for your contribution @DoubleDi! I'm merging this PR to main branch. |
This PR improves the performance of Abs() and Round() and is related to #208 .
The goal is to return the original value instead of creating a new one when: