3v4l.org

run code in 300+ PHP versions simultaneously
<?php function returnTime(callable $function) { $count = 100; $repeat = 100; $tests = []; for ($i = 0; $i < $repeat; $i++) { $tests[$i] = []; for ($i = 0; $i < $count; $i++) { $startTime = microtime(true); $function(); $endTime = microtime(true); $tests[$i][] = $endTime - $startTime; } } foreach ($tests as &$test) $test = array_sum($test); return array_sum($tests) / $repeat; } function compareResults($result1, $name1, $result2, $name2) { $results = [ $result1, $result2, ]; $names = [ $name1, $name2, ]; if ($results[0] == $results[1]) { return 0; } if ($results[0] < $results[1]) { $fasterIndex = 0; } else { $fasterIndex = 1; } $slowerIndex = 1 - $fasterIndex; $fasterResult = $results[$fasterIndex]; $slowerResult = $results[$slowerIndex]; echo "{$names[$fasterIndex]} performs faster than {$names[$slowerIndex]}.", PHP_EOL; echo "It is ", round(($slowerResult / $fasterResult) * 100 - 100), "% faster.", PHP_EOL; } // Array with 500000 elements $array = array_fill(0, 500000, 1); compareResults( returnTime(function () use ($array) { end($array); $lastKey = key($array); reset($array); }), "end()", returnTime(function () use ($array) { $lastKey = key(array_slice($array, -1, 1, true)); }), "array_slice()" );

Abusive script

This script was stopped while abusing our resources

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.110.3310.09636.25
8.2.00.3080.10835.41
8.1.240.0210.01335.59
8.1.110.0250.01534.72
7.4.41.2360.81746.75
7.4.31.2740.76747.00
7.4.21.4450.83746.67
7.4.11.3390.88246.83
7.4.01.2080.93147.03
7.3.161.2070.75046.59
7.3.151.2830.75846.91
7.3.141.4780.86046.85
7.3.131.4380.78546.75
7.3.121.2790.85846.83
7.3.111.3220.93446.96
7.3.101.3370.90346.64
7.3.91.1370.82446.85
7.3.81.0860.67245.79
7.3.71.0290.71845.54
7.3.61.0630.69845.53
7.3.51.1370.72245.50
7.3.41.0960.71445.54
7.3.31.0550.70745.57
7.3.20.8210.72248.51
7.3.10.3160.68648.49
7.3.00.3060.71248.30
7.2.291.2100.85746.99
7.2.281.2100.79946.85
7.2.271.4190.87146.96
7.2.261.3880.88447.02
7.2.251.5350.84946.96
7.2.241.4490.77046.92
7.2.231.4130.93346.91
7.2.221.2320.84846.95
7.2.211.0730.69446.02
7.2.201.0410.70945.90
7.2.191.0490.70045.75
7.2.181.1320.68545.67
7.2.171.1110.68345.84
7.2.161.0960.68245.74
7.2.150.6690.70048.77
7.2.140.3150.70148.89
7.2.130.3080.71548.84
7.2.120.3380.69748.79
7.2.110.3160.71348.77
7.2.100.3050.69048.84
7.2.90.3070.73748.98
7.2.80.3750.77748.84
7.2.70.3850.73348.72
7.2.60.4680.76348.76
7.2.50.4330.73848.84
7.2.40.3220.72448.92
7.2.30.3320.67148.80
7.2.20.3250.69348.95
7.2.10.3090.70148.67
7.2.00.3600.70448.93
7.1.331.8120.56747.33
7.1.321.7260.71247.61
7.1.312.0510.35745.56
7.1.301.5360.39746.05
7.1.291.5600.47046.11
7.1.281.3600.64046.90
7.1.270.7010.71447.68
7.1.260.3160.70447.56
7.1.250.2910.71947.76

preferences:
42.8 ms | 403 KiB | 5 Q