Skip to content

Refactor bcmath 2 #14110

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

Closed
wants to merge 2 commits into from
Closed

Conversation

SakiTakamachi
Copy link
Member

benchmark: #14076

before:

1.6825220584869
2.0993950366974
2.1744661331177

use UNEXPECTED:

1.6566438674927
2.0563621520996
2.1560161113739

use memset:

1.6639218330383
1.9661808013916
2.0960700511932

The difference is small, so it would be helpful if someone also could try it on.

@SakiTakamachi SakiTakamachi marked this pull request as ready for review May 2, 2024 12:44
@SakiTakamachi SakiTakamachi requested a review from Girgias as a code owner May 2, 2024 12:44
@SakiTakamachi SakiTakamachi requested a review from nielsdos May 2, 2024 12:44
Comment on lines +67 to +74
size_t scale_diff;
if (scale > num->n_scale && (scale_diff = scale - num->n_scale) > 8) {
memset(sptr, BCD_CHAR(0), scale_diff);
sptr += scale_diff;
} else {
for (size_t index = num->n_scale; index < scale; index++) {
*sptr++ = BCD_CHAR(0);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's safe to always compute scale_diff, the compiler will do the optimization for you, and it will also be cleaner code.
Anyway, this part didn't make a real difference on my system, the UNEXPECTED part did however make an improvement.

To have more stable measurements, I recommend using hyperfine which is what I typically use. It runs the code multiple times and also computes a confidence interval. It can also do warmup rounds to reduce noise. I found the results from this tool to be more stable than only using the benchmark script. To use it here I would recommend to reduce the number of iterations in your benchmark script (to make sure the total runtime is below a second to avoid CPU throttling), and to remove the timing from the benchmark script and only rely on hyperfine instead.

@SakiTakamachi
Copy link
Member Author

After #14115 is merged, I'll check if it's still effective.

@SakiTakamachi
Copy link
Member Author

I'm closing this PR because the results are no longer changing (in fact, they are a little slower).

@SakiTakamachi SakiTakamachi deleted the refactor_bcmath_2 branch May 4, 2024 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants