Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improve performance of intval('+0b...', 2) and intval('0b...', 2) #20357

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
ndossche wants to merge 1 commit into php:master
base: master
Choose a base branch
Loading
from ndossche:intval-bin-opt

Conversation

@ndossche
Copy link
Member

@ndossche ndossche commented Nov 2, 2025
edited
Loading

For this benchmark:

<?php
for ($i = 0; $i < 10000000; $i++) {
 intval('+0b11111111111100000000', 2);
}

On an i7-4790:

Benchmark 1: ./sapi/cli/php x.php
 Time (mean ± σ): 527.3 ms ± 8.1 ms [User: 523.5 ms, System: 2.4 ms]
 Range (min ... max): 515.4 ms ... 545.1 ms 10 runs
Benchmark 2: ./sapi/cli/php_old x.php
 Time (mean ± σ): 629.3 ms ± 6.0 ms [User: 625.9 ms, System: 1.8 ms]
 Range (min ... max): 622.8 ms ... 643.2 ms 10 runs
Summary
 ./sapi/cli/php x.php ran
 1.19 ± 0.02 times faster than ./sapi/cli/php_old x.php

On an i7-1185G7:

Benchmark 1: ./sapi/cli/php x.php
 Time (mean ± σ): 429.6 ms ± 7.2 ms [User: 427.5 ms, System: 1.6 ms]
 Range (min ... max): 423.0 ms ... 449.0 ms 10 runs
 
Benchmark 2: ./sapi/cli/php_old x.php
 Time (mean ± σ): 486.0 ms ± 10.7 ms [User: 479.2 ms, System: 2.3 ms]
 Range (min ... max): 476.4 ms ... 507.3 ms 10 runs
 
Summary
 ./sapi/cli/php x.php ran
 1.13 ± 0.03 times faster than ./sapi/cli/php_old x.php

For this benchmark:
```php
<?php
for ($i = 0; $i < 10000000; $i++) {
 intval('+0b11111111111100000000', 2);
}
```
On an i7-4790:
```
Benchmark 1: ./sapi/cli/php x.php
 Time (mean ± σ): 527.3 ms ± 8.1 ms [User: 523.5 ms, System: 2.4 ms]
 Range (min ... max): 515.4 ms ... 545.1 ms 10 runs
Benchmark 2: ./sapi/cli/php_old x.php
 Time (mean ± σ): 629.3 ms ± 6.0 ms [User: 625.9 ms, System: 1.8 ms]
 Range (min ... max): 622.8 ms ... 643.2 ms 10 runs
Summary
 ./sapi/cli/php x.php ran
 1.19 ± 0.02 times faster than ./sapi/cli/php_old x.php
```
@ndossche ndossche marked this pull request as ready for review November 2, 2025 12:00
Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

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

This looks correct to me, but I think this has reminded me that intval() doesn't support the recent octal prefix addition, so 0o14 would be returned as 0 rather than 12.

Which is somehow missed when working on the RFC as some other related functions already supported the syntax :/

Copy link
Member Author

ndossche commented Nov 2, 2025

This looks correct to me, but I think this has reminded me that intval() doesn't support the recent octal prefix addition, so 0o14 would be returned as 0 rather than 12.

Yeah you're correct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Girgias Girgias Girgias approved these changes

@bukka bukka Awaiting requested review from bukka bukka is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /