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); });
Output for 8.2.9
Duration of array_slice() + key(): 0.00024318695068359 Duration of end() + key(): 1.9565486907959 Duration of array_key_last(): 0.00014305114746094 Duration of array_keys() + end(): 1.8369197845459 Duration of array_reverse() + key(): 1.9942331314087 Duration of array_slice() + foreach(): 0.00022411346435547
Output for 7.3.7
Duration of array_slice() + key(): 0.30515670776367 Duration of end() + key(): 4.9277305603027 Duration of array_key_last(): 0.00028133392333984 Duration of array_keys() + end(): 5.1175451278687 Duration of array_reverse() + key(): 4.916205406189 Duration of array_slice() + foreach(): 0.28143405914307
Output for 7.3.6
Duration of array_slice() + key(): 0.25864601135254 Duration of end() + key(): 4.5955657958984 Duration of array_key_last(): 0.00017642974853516 Duration of array_keys() + end(): 3.8457107543945 Duration of array_reverse() + key(): 4.0345478057861 Duration of array_slice() + foreach(): 0.25873184204102
Output for 7.3.5
Duration of array_slice() + key(): 0.26666164398193 Duration of end() + key(): 4.8836326599121 Duration of array_key_last(): 0.00018119812011719 Duration of array_keys() + end(): 4.9739265441895 Duration of array_reverse() + key(): 5.4063606262207 Duration of array_slice() + foreach(): 0.26681900024414
Output for 7.3.4
Duration of array_slice() + key(): 0.29699325561523 Duration of end() + key(): 4.9526739120483 Duration of array_key_last(): 0.00013351440429688 Duration of array_keys() + end(): 4.7189474105835 Duration of array_reverse() + key(): 5.1905870437622 Duration of array_slice() + foreach(): 0.27610778808594
Output for 7.3.3
Duration of array_slice() + key(): 0.29860973358154 Duration of end() + key(): 4.6753787994385 Duration of array_key_last(): 0.00012397766113281 Duration of array_keys() + end(): 4.4854879379272 Duration of array_reverse() + key(): 4.4885349273682 Duration of array_slice() + foreach(): 0.27184009552002
Output for 7.3.2
Duration of array_slice() + key(): 0.25417804718018 Duration of end() + key(): 2.3061895370483 Duration of array_key_last(): 0.00021934509277344 Duration of array_keys() + end(): 1.8089628219604 Duration of array_reverse() + key(): 1.9952487945557 Duration of array_slice() + foreach(): 0.2450704574585
Output for 7.3.1
Duration of array_slice() + key(): 0.26472568511963 Duration of end() + key(): 2.387638092041 Duration of array_key_last(): 0.00023841857910156 Duration of array_keys() + end(): 1.7866182327271 Duration of array_reverse() + key(): 2.5418519973755 Duration of array_slice() + foreach(): 0.27650833129883
Output for 7.3.0
Duration of array_slice() + key(): 0.30954360961914 Duration of end() + key(): 2.2660303115845 Duration of array_key_last(): 0.00014305114746094 Duration of array_keys() + end(): 1.9052600860596 Duration of array_reverse() + key(): 2.8449773788452 Duration of array_slice() + foreach(): 0.35722255706787
Output for 7.2.20
Duration of array_slice() + key(): 0.27368068695068 Duration of end() + key(): 5.1148509979248 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.19
Duration of array_slice() + key(): 0.27237415313721 Duration of end() + key(): 5.0911235809326 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.18
Duration of array_slice() + key(): 0.26814460754395 Duration of end() + key(): 4.9553251266479 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.17
Duration of array_slice() + key(): 0.41909217834473 Duration of end() + key(): 4.9076557159424 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.16
Duration of array_slice() + key(): 0.4109001159668 Duration of end() + key(): 5.2420282363892 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.15
Duration of array_slice() + key(): 0.24130821228027 Duration of end() + key(): 1.9095230102539 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.14
Duration of array_slice() + key(): 0.26928901672363 Duration of end() + key(): 2.7032566070557 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.13
Duration of array_slice() + key(): 0.42280673980713 Duration of end() + key(): 2.5822639465332 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.12
Duration of array_slice() + key(): 0.25760173797607 Duration of end() + key(): 2.3777151107788 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.11
Duration of array_slice() + key(): 0.28550148010254 Duration of end() + key(): 2.0692777633667 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.10
Duration of array_slice() + key(): 0.27139186859131 Duration of end() + key(): 2.4012756347656 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.9
Duration of array_slice() + key(): 0.28322696685791 Duration of end() + key(): 2.0989036560059 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.8
Duration of array_slice() + key(): 0.29898166656494 Duration of end() + key(): 2.3763990402222 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.7
Duration of array_slice() + key(): 0.32982349395752 Duration of end() + key(): 2.4386596679688 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.6
Duration of array_slice() + key(): 0.28162956237793 Duration of end() + key(): 1.9515323638916 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.5
Duration of array_slice() + key(): 0.28419971466064 Duration of end() + key(): 2.0516920089722 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.4
Duration of array_slice() + key(): 0.2574348449707 Duration of end() + key(): 1.9310760498047 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.3
Duration of array_slice() + key(): 0.26096343994141 Duration of end() + key(): 2.1079874038696 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.2
Duration of array_slice() + key(): 0.28133869171143 Duration of end() + key(): 2.1362686157227 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.1
Duration of array_slice() + key(): 0.27779579162598 Duration of end() + key(): 2.0365142822266 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.2.0
Duration of array_slice() + key(): 0.2507495880127 Duration of end() + key(): 2.4284744262695 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.1.30
Duration of array_slice() + key(): 0.26890277862549 Duration of end() + key(): 15.840158462524 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.1.29
Duration of array_slice() + key(): 0.26249885559082 Duration of end() + key(): 6.420783996582 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.1.28
Duration of array_slice() + key(): 0.28366088867188 Duration of end() + key(): 2.2159576416016 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.1.27
Duration of array_slice() + key(): 0.29645919799805 Duration of end() + key(): 2.4740600585938 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.1.26
Duration of array_slice() + key(): 0.2817964553833 Duration of end() + key(): 2.537317276001 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.
Output for 7.1.25
Duration of array_slice() + key(): 0.3520679473877 Duration of end() + key(): 2.203426361084 Duration of array_key_last(): Fatal error: Uncaught Error: Call to undefined function array_key_last() in /in/aguPF:34 Stack trace: #0 /in/aguPF(10): {closure}() #1 /in/aguPF(35): returnTime(Object(Closure)) #2 {main} thrown in /in/aguPF on line 34
Process exited with code 255.

preferences:
61.67 ms | 402 KiB | 41 Q