3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (PHP_VERSION !== '7.0.0RC4') { exit('done'); } class Bench { protected $functions = []; public function add($label, \Closure $function) { $this->functions[] = [$label, $function]; } public function run($count) { $function = function () {}; $stats = $this->getStats(); for ($i = $count; $i--;) $function(); $stats2 = $this->getStats(); $timeDiff = $stats2[4] - $stats[4]; $this->printStats('Empty run (time subtracted from real runs)', $stats, $stats2, 0); // TODO: Split runs in pieces and interleave, to avoid bias with first/last runner. foreach ($this->functions as list($label, $function)) { $stats = $this->getStats(); for ($i = $count; $i--;) $function(); $stats2 = $this->getStats(); $this->printStats($label, $stats, $stats2, $timeDiff); } } protected function getStats() { return [memory_get_usage(), memory_get_usage(true), memory_get_peak_usage(), memory_get_peak_usage(true), microtime(1)]; } protected function printStats($label, $stats1, $stats2, $timeDiff) { list($mem, $memReal, $memPeak, $memRealPeak, $time) = $stats1; list($memNew, $memRealNew, $memPeakNew, $memRealPeakNew, $timeNew) = $stats2; $nl = "\n"; $labelLength = 20; $resultsLength = 15; echo '<p><b>' . $label . ':</b></p>' . $nl; echo '<code><p>' . $nl; echo str_pad('Memory', $labelLength, '.', STR_PAD_RIGHT); echo str_pad(number_format(($memNew - $mem) >> 10, 0), $resultsLength, '.', STR_PAD_LEFT) . ' kb<br>' . $nl; echo str_pad('Memory Real', $labelLength, '.', STR_PAD_RIGHT); echo str_pad(number_format(($memRealNew - $memReal) >> 10, 0), $resultsLength, '.', STR_PAD_LEFT) . ' kb<br>' . $nl; echo str_pad('Memory Peak', $labelLength, '.', STR_PAD_RIGHT); echo str_pad(number_format(($memPeakNew - $memPeak) >> 10, 0), $resultsLength, '.', STR_PAD_LEFT) . ' kb<br>' . $nl; echo str_pad('Memory Real Peak', $labelLength, '.', STR_PAD_RIGHT); echo str_pad(number_format(($memRealPeakNew - $memRealPeak) >> 10, 0), $resultsLength, '.', STR_PAD_LEFT) . ' kb<br>' . $nl; echo str_pad('Time', $labelLength, '.', STR_PAD_RIGHT); echo str_pad(number_format($timeNew - $time - $timeDiff, 5), $resultsLength, '.', STR_PAD_LEFT); echo ' sec' . $nl . '</code></p>' . $nl . $nl; } } $f1 = function ($input) { return $input * 10; }; $f2 = function ($input) { return [true, $input * 10]; }; $b = new Bench(); $b->add('single', function () use ($f1) { $value = $f1(10); }); $b->add('tuple', function () use ($f2) { list($error, $value) = $f2(10); }); $b->run(40000);

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.2.00.0000.01219.10
7.1.100.0060.00618.06
7.1.70.0080.00317.16
7.1.60.0040.01819.50
7.1.50.0140.01016.77
7.1.00.0030.07722.45
7.0.200.0040.00416.69
7.0.100.0100.06720.11
7.0.90.0200.07719.97
7.0.80.0030.07320.02
7.0.70.0270.03720.00
7.0.60.0100.08319.97
7.0.50.0200.07320.25
7.0.40.0100.04020.03
7.0.30.0030.04320.00
7.0.20.0070.04020.07
7.0.10.0070.03719.95
7.0.00.0100.03320.00
5.6.280.0030.03021.17
5.6.250.0030.04320.70
5.6.240.0030.07320.70
5.6.230.0030.07020.76
5.6.220.0070.08020.66
5.6.210.0130.07720.59
5.6.200.0070.04321.06
5.6.190.0070.04021.15
5.6.180.0030.04321.09
5.6.170.0030.04321.09
5.6.160.0000.04020.98
5.6.150.0030.03721.14
5.6.140.0030.03721.17
5.6.130.0030.04021.11
5.6.120.0030.03721.06
5.6.110.0030.04021.09
5.6.100.0000.04021.07
5.6.90.0070.03720.96
5.6.80.0030.03320.46
5.6.70.0000.03720.50
5.6.60.0030.03320.43
5.6.50.0070.03320.45
5.6.40.0030.04020.35
5.6.30.0100.02720.42
5.6.20.0030.03320.39
5.6.10.0070.04020.35
5.6.00.0130.05320.39
5.5.380.0130.07720.58
5.5.370.0100.06020.40
5.5.360.0070.06320.38
5.5.350.0070.08020.38
5.5.340.0200.02320.80
5.5.330.0130.03020.87
5.5.320.0070.04020.96
5.5.310.0000.04720.96
5.5.300.0070.03720.91
5.5.290.0030.04320.81
5.5.280.0030.03720.76
5.5.270.0070.03320.91
5.5.260.0100.03020.95
5.5.250.0000.04020.77
5.5.240.0030.03320.20
5.5.230.0000.04320.25
5.5.220.0030.03720.31
5.5.210.0070.03020.28
5.5.200.0030.03320.22
5.5.190.0100.02720.26
5.5.180.0000.03720.27
5.5.160.0000.05020.30
5.5.150.0100.05320.21
5.5.140.0070.04020.27
5.5.130.0130.07020.25
5.5.120.0170.05720.25
5.5.110.0100.04320.17
5.5.100.0100.06320.20
5.5.90.0030.03720.20
5.5.80.0030.04719.98
5.5.70.0070.04020.09
5.5.60.0130.06320.07
5.5.50.0030.08320.18
5.5.40.0070.04320.07
5.5.30.0070.08020.11
5.5.20.0070.05020.11
5.5.10.0070.07720.13
5.5.00.0100.07720.16
5.4.450.0130.04019.52
5.4.440.0070.03019.45
5.4.430.0000.04019.42
5.4.420.0130.03019.41
5.4.410.0030.03319.23
5.4.400.0070.03019.21
5.4.390.0070.03019.10
5.4.380.0000.04319.09
5.4.370.0030.03719.13
5.4.360.0130.02319.05
5.4.350.0030.03719.18
5.4.340.0100.03019.18
5.4.320.0070.08018.91
5.4.310.0030.03718.95
5.4.300.0070.03318.90
5.4.290.0100.05719.16
5.4.280.0070.07319.12
5.4.270.0030.06719.04
5.4.260.0130.06319.13
5.4.250.0070.06318.87
5.4.240.0100.05319.20
5.4.230.0030.07019.12
5.4.220.0030.03719.02
5.4.210.0130.06019.04
5.4.200.0030.05319.02
5.4.190.0000.08319.02
5.4.180.0130.07019.20
5.4.170.0070.07719.17
5.4.160.0030.03719.02
5.4.150.0130.07018.89
5.4.140.0100.03316.49
5.4.130.0000.07316.40
5.4.120.0070.03316.32
5.4.110.0030.03716.52
5.4.100.0070.03016.32
5.4.90.0030.07716.41
5.4.80.0030.04716.55
5.4.70.0100.06716.40
5.4.60.0030.03316.41
5.4.50.0100.07016.37
5.4.40.0070.05016.54
5.4.30.0100.06716.45
5.4.20.0030.05716.46
5.4.10.0000.03716.46
5.4.00.0130.02715.85

preferences:
36.42 ms | 401 KiB | 5 Q