Skip to content

Conversation

@ndossche
Copy link
Member

@ndossche ndossche commented Oct 31, 2025

For this benchmark script:

<?php

function sum($a, $b) {
    return $a+$b;
}

$cb = sum(...);

for ($i = 0; $i < 1000000; $i++) {
    array_map($cb, [1,2,3], [4,5,6]);
}

On an i7-4790:

Benchmark 1: ./sapi/cli/php x.php
  Time (mean ± σ):     171.9 ms ±   2.1 ms    [User: 168.6 ms, System: 2.3 ms]
  Range (min … max):   168.8 ms … 176.1 ms    17 runs
 
Benchmark 2: ./sapi/cli/php_old x.php
  Time (mean ± σ):     206.3 ms ±   4.1 ms    [User: 201.8 ms, System: 2.7 ms]
  Range (min … max):   201.8 ms … 217.3 ms    14 runs
 
Summary
  ./sapi/cli/php x.php ran
    1.20 ± 0.03 times faster than ./sapi/cli/php_old x.php

On an i7-1185G7:

Benchmark 1: ./sapi/cli/php x.php
  Time (mean ± σ):      98.9 ms ±   2.0 ms    [User: 97.3 ms, System: 1.4 ms]
  Range (min … max):    96.3 ms … 102.8 ms    30 runs
 
Benchmark 2: ./sapi/cli/php_old x.php
  Time (mean ± σ):     122.1 ms ±   1.0 ms    [User: 120.0 ms, System: 1.9 ms]
  Range (min … max):   120.8 ms … 123.9 ms    24 runs
 
Summary
  ./sapi/cli/php x.php ran
    1.23 ± 0.03 times faster than ./sapi/cli/php_old x.php

Since this will be copied on the call frame, a refcounted copy is not
necessary.
This makes the code more compact, and less weird: the stub doesn't
indicate that this function can return NULL.
@ndossche ndossche marked this pull request as ready for review November 1, 2025 07:55
@ndossche ndossche requested a review from bukka as a code owner November 1, 2025 07:55
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.

2 participants