Skip to content

ext/bcmath: use vector in compare #18859

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SakiTakamachi
Copy link
Member

Benchmark

The theoretical expectation is that it should be just slightly slower with small values, but in practice, it seems almost unchanged.

Small value

for ($i = 0; $i < 10000000; $i++) {
    bccomp('1.2345', '1.23456', 5);
}
Benchmark 1: /php-dev2/sapi/cli/php /mount/bc/cmp/0.php
  Time (mean ± σ):     439.0 ms ±   2.6 ms    [User: 433.7 ms, System: 2.9 ms]
  Range (min … max):   434.4 ms … 444.2 ms    10 runs
 
Benchmark 2: /master/sapi/cli/php /mount/bc/cmp/0.php
  Time (mean ± σ):     443.4 ms ±   5.5 ms    [User: 437.4 ms, System: 3.5 ms]
  Range (min … max):   434.0 ms … 452.2 ms    10 runs
 
Summary
  '/php-dev2/sapi/cli/php /mount/bc/cmp/0.php' ran
    1.01 ± 0.01 times faster than '/master/sapi/cli/php /mount/bc/cmp/0.php'

Middle value 1

for ($i = 0; $i < 10000000; $i++) {
    bccomp('1.234567890123', '1.234567890123', 15);
}
Benchmark 1: /php-dev2/sapi/cli/php /mount/bc/cmp/1.php
  Time (mean ± σ):     475.9 ms ±   1.7 ms    [User: 469.5 ms, System: 3.9 ms]
  Range (min … max):   472.0 ms … 477.4 ms    10 runs
 
Benchmark 2: /master/sapi/cli/php /mount/bc/cmp/1.php
  Time (mean ± σ):     489.9 ms ±   4.3 ms    [User: 483.9 ms, System: 3.5 ms]
  Range (min … max):   485.0 ms … 497.7 ms    10 runs
 
Summary
  '/php-dev2/sapi/cli/php /mount/bc/cmp/1.php' ran
    1.03 ± 0.01 times faster than '/master/sapi/cli/php /mount/bc/cmp/1.php'

Middle value 2

for ($i = 0; $i < 10000000; $i++) {
    bccomp('1.23456789012345678901234567890123456789012345678901234567890123456789', '1.23456789012345678901234567890123456789012345678901234567890123456789', 40);
}
Benchmark 1: /php-dev2/sapi/cli/php /mount/bc/cmp/2.php
  Time (mean ± σ):     492.9 ms ±   3.0 ms    [User: 486.2 ms, System: 4.3 ms]
  Range (min … max):   487.9 ms … 498.1 ms    10 runs
 
Benchmark 2: /master/sapi/cli/php /mount/bc/cmp/2.php
  Time (mean ± σ):     590.1 ms ±   2.9 ms    [User: 584.2 ms, System: 3.4 ms]
  Range (min … max):   585.6 ms … 593.9 ms    10 runs
 
Summary
  '/php-dev2/sapi/cli/php /mount/bc/cmp/2.php' ran
    1.20 ± 0.01 times faster than '/master/sapi/cli/php /mount/bc/cmp/2.php'

Large value

for ($i = 0; $i < 100000; $i++) {
    bccomp(str_repeat('1234567890', 3000), str_repeat('1234567890', 3000), 0);
}
Benchmark 1: /php-dev2/sapi/cli/php /mount/bc/cmp/3.php
  Time (mean ± σ):     571.7 ms ±  22.2 ms    [User: 566.5 ms, System: 2.8 ms]
  Range (min … max):   561.6 ms … 634.5 ms    10 runs

Benchmark 2: /master/sapi/cli/php /mount/bc/cmp/3.php
  Time (mean ± σ):      1.322 s ±  0.002 s    [User: 1.316 s, System: 0.004 s]
  Range (min … max):    1.319 s …  1.326 s    10 runs
 
Summary
  '/php-dev2/sapi/cli/php /mount/bc/cmp/3.php' ran
    2.31 ± 0.09 times faster than '/master/sapi/cli/php /mount/bc/cmp/3.php'

@SakiTakamachi SakiTakamachi marked this pull request as ready for review June 16, 2025 13: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