3v4l.org

run code in 300+ PHP versions simultaneously
<?php function returnTime(callable $function, int $repeat = 50) { $tests = []; for ($i = 0; $i < $repeat; ++$i) { $startTime = microtime(true); $function(); $endTime = microtime(true); $tests[] = $endTime - $startTime; } // Representing the average return 1000 * array_sum($tests) / $repeat; } $array = array_fill(0, 200000, 1); echo "Duration of array_slice() + key(): ", returnTime(function() use ($array) { $lastKey = key(array_slice($array, -1, 1, true)); }); echo PHP_EOL; echo "Duration of end() + key(): " , returnTime(function() use ($array){ end($array); $lastKey = key($array); }); echo PHP_EOL; echo "Duration of array_key_last(): " , returnTime(function() use ($array){ $lastKey = array_key_last($array); }); echo PHP_EOL; echo "Duration of array_keys() + end(): " , returnTime(function() use ($array){ $keys = array_keys($array); $last = end($keys); }); echo PHP_EOL; echo "Duration of array_reverse() + key(): " , returnTime(function() use ($array){ $key = key(array_reverse($array)); }); echo PHP_EOL; echo "Duration of array_slice() + foreach(): " , returnTime(function() use ($array){ foreach (array_slice($array, -1, 1, true) as $key => $value); });

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.2.90.2590.07023.71
7.3.70.5390.26026.71
7.3.60.3520.31626.96
7.3.50.5210.28926.82
7.3.40.5070.26526.82
7.3.30.4870.24526.48
7.3.20.1020.25332.29
7.3.10.0960.27432.45
7.3.00.1490.25832.51
7.2.200.1740.12027.20
7.2.190.1600.11327.11
7.2.180.1910.08727.07
7.2.170.1790.10026.85
7.2.160.1890.11627.03
7.2.150.0420.08232.48
7.2.140.0580.10532.87
7.2.130.0500.12332.70
7.2.120.0430.11332.68
7.2.110.0380.09932.84
7.2.100.0530.10032.68
7.2.90.0330.10732.60
7.2.80.0440.10532.75
7.2.70.0520.10032.64
7.2.60.0370.09632.73
7.2.50.0540.08032.96
7.2.40.0270.10632.54
7.2.30.0480.09232.43
7.2.20.0280.11532.34
7.2.10.0420.09132.70
7.2.00.0500.10932.51
7.1.300.6890.10729.45
7.1.290.2560.09031.72
7.1.280.0490.09631.88
7.1.270.0550.10431.59
7.1.260.0440.10931.76
7.1.250.0450.09431.36

preferences:
32.26 ms | 403 KiB | 5 Q