3v4l.org

run code in 300+ PHP versions simultaneously
<?php const TESTS_TO_RUN = 10; const NUMBERS_TO_SUM = 10000; function displayTabularData($itemList) { // Header $testAmounts = reset(reset($itemList)); printf("%11s", ' '); foreach($testAmounts as $key => $value) printf("[%10s]", $key); echo PHP_EOL; // Info foreach($itemList as $item) { $results = array_shift($item); $name = array_shift($item); printf("[%10s]", $name); foreach ($results as $key => $value) { printf("%.8f, ", $value); } echo PHP_EOL; } } function getRunningTime(callable $callback, $size) { $ts = microtime(); call_user_func($callback, $size); $time = microtime() - $ts; return $time; } function benchmarkCallback(callable $callback, $tests = TESTS_TO_RUN, $step = NUMBERS_TO_SUM) { $collection = []; for($size = $step; $size <= $tests * $step; $size += $step) { $collection[$size] = getRunningTime($callback, $size); } return $collection; } $imperative = function ($size) { for ($sum = 0, $i = 1; $i <= $size; $sum += $i, $i++); }; $functional = function ($size) { array_sum(range(1, $size)); }; displayTabularData([ [benchmarkCallback($imperative), 'Imperative'], [benchmarkCallback($functional), 'Functional'] ]);

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)
7.1.70.0160.01421.00
7.1.60.0070.04521.19
7.1.50.0070.02120.57
7.1.00.0030.10326.48
7.0.200.0200.02020.93
7.0.70.0330.09324.76
7.0.60.0230.07724.55
7.0.50.0300.10324.92
7.0.40.0100.11323.06
7.0.30.0130.11023.17
7.0.20.0200.10323.10
7.0.10.0200.10023.05
7.0.00.0170.10023.17
5.6.280.0230.17734.83
5.6.220.0170.15734.52
5.6.210.0300.17334.40
5.6.200.0130.13034.88
5.6.190.0200.17734.97
5.6.180.0270.17734.92
5.6.170.0170.11335.31
5.6.160.0230.17034.95
5.6.150.0270.13034.91
5.6.140.0270.15334.86
5.6.130.0370.15735.01
5.6.120.0270.18034.77
5.6.110.0100.16334.91
5.6.100.0200.16734.85
5.6.90.0270.18334.92
5.6.80.0200.17034.25
5.6.70.0270.13034.32
5.6.60.0400.14034.38
5.6.50.0370.18334.39
5.6.40.0300.17334.23
5.6.30.0370.17334.23
5.6.20.0130.17334.36
5.6.10.0200.19034.15
5.6.00.0370.17034.19
5.5.360.0370.17734.19
5.5.350.0430.11734.29
5.5.340.0300.17034.62
5.5.330.0500.16034.60
5.5.320.0170.17034.73
5.5.310.0300.14034.67
5.5.300.0230.15734.63
5.5.290.0230.14734.71
5.5.280.0330.18034.73
5.5.270.0170.14034.56
5.5.260.0230.16734.56
5.5.250.0230.19734.45
5.5.240.0270.17034.03
5.5.230.0100.19333.95
5.5.220.0230.12333.99
5.5.210.0200.15334.13
5.5.200.0270.13734.03
5.5.190.0430.17734.08
5.5.180.0470.15333.99
5.5.160.0230.18034.10
5.5.150.0230.16333.98
5.5.140.0330.15334.05
5.5.130.0270.18034.05
5.5.120.0200.19334.11
5.5.110.0200.17734.05
5.5.100.0200.16333.92
5.5.90.0330.17733.99
5.5.80.0300.18033.99
5.5.70.0370.15733.96
5.5.60.0330.15733.93
5.5.50.0230.17733.89
5.5.40.0270.15333.97
5.5.30.0070.09334.39
5.5.20.0200.14033.77
5.5.10.0300.18033.98
5.5.00.0300.18333.81
5.4.450.0270.17733.17
5.4.440.0300.17033.14
5.4.430.0300.18333.08
5.4.420.0270.16333.12
5.4.410.0230.17732.93
5.4.400.0230.17732.80
5.4.390.0270.15732.98
5.4.380.0100.15332.79
5.4.370.0530.15332.66
5.4.360.0430.15332.80
5.4.350.0300.15032.63
5.4.340.0370.16032.81
5.4.320.0200.11732.73
5.4.310.0170.14332.76
5.4.300.0170.16332.84
5.4.290.0400.16732.95
5.4.280.0130.17032.63
5.4.270.0330.16032.84
5.4.260.0270.18032.83
5.4.250.0270.12332.80
5.4.240.0300.16332.67
5.4.230.0100.16332.66
5.4.220.0100.17032.80
5.4.210.0200.13732.88
5.4.200.0200.10032.86
5.4.190.0100.09732.81
5.4.180.0370.17332.82
5.4.170.0330.17732.77
5.4.160.0400.17032.79
5.4.150.0300.13332.77
5.4.140.0170.17730.58
5.4.130.0100.14730.47
5.4.120.0200.11330.19
5.4.110.0300.10730.17
5.4.100.0230.13330.16
5.4.90.0170.11330.30
5.4.80.0370.12030.30
5.4.70.0300.14730.27
5.4.60.0270.14730.08
5.4.50.0370.10730.26
5.4.40.0130.11730.21
5.4.30.0330.15730.20
5.4.20.0130.11330.18
5.4.10.0330.14330.20
5.4.00.0130.11329.52
5.3.290.0030.08014.82
5.3.280.0030.04314.61
5.3.270.0130.07314.54
5.3.260.0000.06014.73
5.3.250.0000.05314.70
5.3.240.0030.08314.68
5.3.230.0100.03014.70
5.3.220.0070.06314.54
5.3.210.0030.04014.63
5.3.200.0030.05314.51
5.3.190.0030.04314.61
5.3.180.0070.03314.57
5.3.170.0030.03714.63
5.3.160.0070.04314.56
5.3.150.0030.04314.66
5.3.140.0070.04714.53
5.3.130.0070.03714.53
5.3.120.0030.04014.53
5.3.110.0070.03314.52
5.3.100.0000.04314.00
5.3.90.0000.04014.02
5.3.80.0000.03713.96
5.3.70.0030.03314.01
5.3.60.0100.06014.09
5.3.50.0030.03713.86
5.3.40.0030.03313.97
5.3.30.0030.03313.81
5.3.20.0000.04013.71
5.3.10.0030.03313.80
5.3.00.0030.04013.71
5.2.170.0030.02712.37
5.2.160.0030.05312.37
5.2.150.0030.02712.37
5.2.140.0000.03312.37
5.2.130.0000.03312.37
5.2.120.0030.02712.37
5.2.110.0000.03012.37
5.2.100.0030.02712.37
5.2.90.0030.02712.37
5.2.80.0000.03312.37
5.2.70.0000.03012.37
5.2.60.0000.03012.37
5.2.50.0000.03712.37
5.2.40.0000.03012.37
5.2.30.0030.02712.37
5.2.20.0030.02712.37
5.2.10.0100.02012.37
5.2.00.0000.04312.37
5.1.60.0000.04312.37
5.1.50.0030.02312.37
5.1.40.0000.02312.37
5.1.30.0000.02712.37
5.1.20.0000.03312.37
5.1.10.0030.04712.37
5.1.00.0030.02312.37
5.0.50.0070.01712.37
5.0.40.0000.04012.37
5.0.30.0030.06712.37
5.0.20.0000.04712.37
5.0.10.0000.04712.37
5.0.00.0070.05012.37
4.4.90.0030.01012.37
4.4.80.0000.03012.37
4.4.70.0000.01712.37
4.4.60.0030.01312.37
4.4.50.0000.02012.37
4.4.40.0000.03012.37
4.4.30.0030.01712.37
4.4.20.0000.01712.37
4.4.10.0000.01712.37
4.4.00.0030.05312.37
4.3.110.0070.03012.37
4.3.100.0000.02712.37
4.3.90.0000.04012.37
4.3.80.0000.05312.37
4.3.70.0000.03712.37
4.3.60.0070.02712.37
4.3.50.0000.03012.37
4.3.40.0000.04712.37
4.3.30.0030.03012.37
4.3.20.0000.03712.37
4.3.10.0070.03012.37
4.3.00.0000.03712.37

preferences:
45.15 ms | 1403 KiB | 5 Q