3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL & ~E_NOTICE); ini_set('display_errors', '1'); define('S', 15000); // list Size define('N', 10); // Number of iterations (for benchmark accuracy) // Comment the lines above and uncomment the lines below to pass the parameters in the command line //define('S', (int)$argv[1]); //define('N', (int)$argv[2]); printf("Generating %d elements... ", S); $tsStart = microtime(TRUE); $array = []; for ($i = 0; $i < S; $i ++) { $array[] = [ 'a' => rand(0, 100), 'f' => 0, 'f' => 0, 'l' => 61.60 ]; } printf("Done. Time: %f seconds.\n", microtime(TRUE) - $tsStart); $time = 0; for ($l = 0; $l < N; $l ++) { $ts = microtime(TRUE); $min = min(array_filter(array_column($array, 'a'))); $time += microtime(TRUE) - $ts; } printf("array_filter(): %9.2f seconds/%d iterations. %f seconds/iteration.\n", $time, N, $time/N); $time = 0; for ($l = 0; $l < N; $l ++) { $ts = microtime(TRUE); $min = null; foreach ($array as $val) { if ($min === null || ($val['a'] && $val['a'] < $min)) { $min = $val['a']; } } $time += microtime(TRUE) - $ts; } printf("foreach : %9.2f seconds/%d iterations. %f seconds/iteration.\n", $time, N, $time/N); $time = 0; for ($l = 0; $l < N; $l ++) { $ts = microtime(TRUE); $min = array_reduce($array, function ($min, $val) { return $min === null || ($val['a'] && $val['a'] < $min) ? $val['a'] : $min; }); $time += microtime(TRUE) - $ts; } printf("reduce @deceze: %9.2f seconds/%d iterations. %f seconds/iteration.\n", $time, N, $time/N); $time = 0; for ($l = 0; $l < N; $l ++) { $ts = microtime(TRUE); $min = array_reduce( $array, function($acc, array $item) { return min($acc, $item['a'] ?: INF); }, INF ); $time += microtime(TRUE) - $ts; } printf("reduce @axiac : %9.2f seconds/%d iterations. %f seconds/iteration.\n", $time, N, $time/N);
Output for git.master_jit
Generating 15000 elements... Done. Time: 0.008978 seconds. array_filter(): 0.01 seconds/10 iterations. 0.000729 seconds/iteration. foreach : 0.01 seconds/10 iterations. 0.001066 seconds/iteration. reduce @deceze: 0.01 seconds/10 iterations. 0.001390 seconds/iteration. reduce @axiac : 0.01 seconds/10 iterations. 0.000950 seconds/iteration.
Output for git.master
Generating 15000 elements... Done. Time: 0.002235 seconds. array_filter(): 0.00 seconds/10 iterations. 0.000460 seconds/iteration. foreach : 0.01 seconds/10 iterations. 0.000780 seconds/iteration. reduce @deceze: 0.01 seconds/10 iterations. 0.001184 seconds/iteration. reduce @axiac : 0.01 seconds/10 iterations. 0.000946 seconds/iteration.
Output for rfc.property-hooks
Generating 15000 elements... Done. Time: 0.002356 seconds. array_filter(): 0.00 seconds/10 iterations. 0.000474 seconds/iteration. foreach : 0.01 seconds/10 iterations. 0.000777 seconds/iteration. reduce @deceze: 0.01 seconds/10 iterations. 0.001160 seconds/iteration. reduce @axiac : 0.01 seconds/10 iterations. 0.000955 seconds/iteration.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
28.36 ms | 409 KiB | 5 Q