Skip to content

ext/bcmath: Improving mul performance 2 #14229

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 9 commits into from

Conversation

SakiTakamachi
Copy link
Member

@SakiTakamachi SakiTakamachi commented May 14, 2024

This is derived from #14213.
Also, I am considering using "Karatsuba-algorithm", but I will separate it into another PR.

bench codes:

1:

$num1 = '1.2345678';
$num2 = '2.1234567';

for ($i = 0; $i < 5000000; $i++) {
    bcmul($num1, $num2, 7);
}

2:

$num1 = str_repeat('1234567890', 300);
$num2 = str_repeat('9876543210', 300);

for ($i = 0; $i < 6000; $i++) {
    bcmul($num1, $num2, 0);
}

3:

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

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

4:

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

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

5:

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

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

before

hyperfine "php /bc/mul/1.php" --warmup 10
Time (mean ± σ):     620.9 ms ±   6.1 ms    [User: 615.4 ms, System: 4.6 ms]
Range (min … max):   612.6 ms … 632.7 ms    10 runs

hyperfine "php /bc/mul/2.php" --warmup 10
Time (mean ± σ):     581.2 ms ±   6.0 ms    [User: 578.2 ms, System: 2.3 ms]
Range (min … max):   571.5 ms … 590.9 ms    10 runs

hyperfine "php /bc/mul/3.php" --warmup 10
Time (mean ± σ):     628.7 ms ±  13.6 ms    [User: 624.9 ms, System: 3.0 ms]
Range (min … max):   614.6 ms … 656.8 ms    10 runs

hyperfine "php /bc/mul/4.php" --warmup 10
Time (mean ± σ):     593.6 ms ±  10.1 ms    [User: 589.6 ms, System: 3.1 ms]
Range (min … max):   583.7 ms … 615.4 ms    10 runs

hyperfine "php /bc/mul/5.php" --warmup 10
Time (mean ± σ):     680.9 ms ±   8.6 ms    [User: 676.8 ms, System: 3.2 ms]
Range (min … max):   671.1 ms … 694.5 ms    10 runs

after

hyperfine "php /bc/mul/1.php" --warmup 10
Time (mean ± σ):     604.5 ms ±   8.7 ms    [User: 600.0 ms, System: 3.5 ms]
Range (min … max):   596.1 ms … 625.3 ms    10 runs

hyperfine "php /bc/mul/2.php" --warmup 10
Time (mean ± σ):     541.1 ms ±   9.0 ms    [User: 537.9 ms, System: 2.4 ms]
Range (min … max):   534.1 ms … 565.5 ms    10 runs

hyperfine "php /bc/mul/3.php" --warmup 10
Time (mean ± σ):     506.8 ms ±   2.9 ms    [User: 502.6 ms, System: 3.3 ms]
Range (min … max):   501.7 ms … 512.0 ms    10 runs

hyperfine "php /bc/mul/4.php" --warmup 10
Time (mean ± σ):     448.6 ms ±   8.1 ms    [User: 444.9 ms, System: 2.9 ms]
Range (min … max):   441.5 ms … 467.7 ms    10 runs

hyperfine "php /bc/mul/5.php" --warmup 10
Time (mean ± σ):     561.4 ms ±   4.4 ms    [User: 557.7 ms, System: 3.0 ms]
Range (min … max):   556.7 ms … 570.7 ms    10 runs

@SakiTakamachi
Copy link
Member Author

I made it a draft because the original hasn't been merged yet.

@SakiTakamachi SakiTakamachi deleted the refactor_bcmath_mul_2 branch June 13, 2024 17:38
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.

1 participant