-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Conversation
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
```
There was a problem hiding this 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 :/
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
Uh oh!
There was an error while loading. Please reload this page.
For this benchmark:
On an i7-4790:
On an i7-1185G7: