Skip to content

ext/bcmath: Made the same changes to _bc_do_add as _bc_do_sub #14196

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

Merged
merged 6 commits into from
May 12, 2024

Conversation

SakiTakamachi
Copy link
Member

benchmark codes:

1:

$num1 = '1.2345678901234567890';
$num2 = '2.12345678901234567890';

for ($i = 0; $i < 4000000; $i++) {
    bcadd($num1, $num2, 20);
}

2:

$num1 = '-12345678901234567890.12345678901234567890';
$num2 = '-212345678901234567890.12345678901234567890';

for ($i = 0; $i < 4000000; $i++) {
    bcadd($num1, $num2, 20);
}

3:

$num1 = '12345678901234567890.00000000000000000000000000000000000000000000000000';
$num2 = '212345678901234567890.00000000000000000000000000000000000000000000000000';

for ($i = 0; $i < 4000000; $i++) {
    bcadd($num1, $num2, 20);
}

before

Time (mean ± σ):     551.0 ms ±  30.3 ms    [User: 547.0 ms, System: 3.1 ms]
Range (min … max):   515.8 ms … 619.9 ms    10 runs

Time (mean ± σ):     666.1 ms ±   7.1 ms    [User: 662.5 ms, System: 2.6 ms]
Range (min … max):   655.2 ms … 679.0 ms    10 runs

Time (mean ± σ):     599.4 ms ±  34.4 ms    [User: 596.0 ms, System: 2.5 ms]
Range (min … max):   565.1 ms … 663.9 ms    10 runs

after

Time (mean ± σ):     515.2 ms ±   5.6 ms    [User: 509.9 ms, System: 4.2 ms]
Range (min … max):   508.5 ms … 526.8 ms    10 runs

Time (mean ± σ):     597.8 ms ±  10.9 ms    [User: 592.1 ms, System: 3.8 ms]
Range (min … max):   586.0 ms … 622.5 ms    10 runs

Time (mean ± σ):     559.5 ms ±  14.5 ms    [User: 554.8 ms, System: 3.6 ms]
Range (min … max):   544.5 ms … 584.3 ms    10 runs

FYI: after the first commit

Time (mean ± σ):     563.6 ms ±  23.4 ms    [User: 559.0 ms, System: 3.5 ms]
Range (min … max):   544.6 ms … 616.3 ms    10 runs

Time (mean ± σ):     637.8 ms ±   5.5 ms    [User: 633.8 ms, System: 3.0 ms]
Range (min … max):   630.0 ms … 646.7 ms    10 runs

Time (mean ± σ):     580.4 ms ±   6.6 ms    [User: 575.3 ms, System: 4.0 ms]
Range (min … max):   574.9 ms … 595.6 ms    10 runs

@SakiTakamachi
Copy link
Member Author

I forgot fixing comments

@SakiTakamachi
Copy link
Member Author

done

@Girgias
Copy link
Member

Girgias commented May 10, 2024

CI is red

@SakiTakamachi
Copy link
Member Author

It looks like the XML test is failing. Merge the latest master

Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

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

Nice work, seems right. Also ran an exhaustive test for the 32-bit case and works fine.
I think it would be good to add a regression test for the issue fixed here though, because the CI didn't catch it (if possible): 64eb41a

@Girgias Girgias removed their request for review May 11, 2024 13:20
@SakiTakamachi
Copy link
Member Author

SakiTakamachi commented May 12, 2024

@nielsdos
I noticed this with Travis.
https://app.travis-ci.com/github/php/php-src/builds/270410835

The other CIs certainly did not detect this.

This is due to a rear overrun, but I can't think of any test to detect this... Do you have any good ideas?

(edit)

I reverted the fix and ran the nightly, but it didn't detect anything.
https://github.com/SakiTakamachi/php-src/actions/runs/9046718030

@SakiTakamachi
Copy link
Member Author

Hmm, I'll merge this for now and add tests later if possible.

@SakiTakamachi SakiTakamachi merged commit 7203ca8 into php:master May 12, 2024
10 checks passed
@SakiTakamachi SakiTakamachi deleted the refactor_bcmath_do_add branch May 12, 2024 06:07
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.

3 participants