Skip to content

improve max() performance #11192

Closed
Closed
@staabm

Description

@staabm

Description

In a recent performance investigation I identified max() as a perf bottleneck in sebastianbergmann/diff#118

@bwoebi chimmed in and suggested max() should be improved at the php-src level.
see his in-detail investigation at sebastianbergmann/diff#118 (comment)

The following code:

<?php
~/php-src-8.2 # time ./sapi/cli/php -r '$b = 1; $c = 2; for ($i = 0; $i < 430000000; ++$i) { $a = max($b, $c); }'

real	0m6.924s
user	0m6.917s
sys	0m0.004s
~/php-src-8.2 # time ./sapi/cli/php -r '$b = 1; $c = 2; for ($i = 0; $i < 430000000; ++$i) { if ($b < $c) { $a = $b; } else { $a = $c; } }'

real	0m2.523s
user	0m2.514s
sys	0m0.008s

max() should be faster

PHP Version

8.2.5

Operating System

macos

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions