3v4l.org

run code in 300+ PHP versions simultaneously
<?php function returnTime(callable $function, int $repeat = 100) { $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, 500000, 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); });

preferences:
39.68 ms | 402 KiB | 5 Q