-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed as not planned
Labels
Description
Description
First class callables feel like the right way to do callbacks since you get propper completion from from your IDE/editor but the performance hit is rather bad. I'm sadly not very familiar with C or PHP internals but would it be possible for opcache to get performance parity with the "string" version of the callbacks? Maybe not for userland functions but at least for internal functions.
<?php
$a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
$s = microtime(true);
for ($i = 0; $i < 100_000; $i++) {
$u = array_map(strtoupper(...), $a);
}
echo (microtime(true) - $s) . PHP_EOL;
$s = microtime(true);
for ($i = 0; $i < 100_000; $i++) {
$u = array_map('strtoupper', $a);
}
echo (microtime(true) - $s) . PHP_EOL;
$s = microtime(true);
for ($i = 0; $i < 100_000; $i++) {
$u = array_map(fn($v) => strtoupper($v), $a);
}
echo (microtime(true) - $s) . PHP_EOL;
3v4l.org with PHP 8.3.13
0.061099052429199
0.026753902435303
0.043981075286865
3v4l.org with git.master
0.051828861236572
0.030702114105225
0.04832911491394