3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @param array $functions An associative array of closures to benchmark * @param int $iterations The number of iterations */ function benchmark($functions, $iterations) { foreach ($functions as $name => $function) { $start = microtime(true); for ($i = 0; $i < $iterations; $i++) { call_user_func($function); } $delta = microtime(true) - $start; echo "$name: " . $delta . "\n"; } } echo "\nBenchmarking \"(array) \$var === \$var\" vs \"is_array(\$var)\" ...\n"; $data = array( 'string', // Not an array array(1, 2, 3), // Small array array_fill(1, 1000, uniqid()) // Large-ish array ); benchmark(array( 'casting' => function () use ($data) { foreach ($data as $d) { $result = (array) $d === $d; } }, 'is_array' => function () use ($data) { foreach ($data as $d) { $result = is_array($d); } } ), 1000); echo "\nBenchmarking \"count(\$var) == 0\" vs \"empty(\$var)\" ...\n"; $data = range(1, 100000); benchmark(array( 'count()' => function () use ($data) { $result = count($data) == 0; }, 'empty()' => function () use ($data) { $result = empty($data); } ), 100000); echo "\nBenchmarking \"array_key_exists(\$key, \$array)\" vs \"\$array[\$key]\" ...\n"; $data = array_fill_keys(range(1, 1000), uniqid()); benchmark(array( 'in_array_keys()' => function () use ($data) { $result = array_key_exists(50, $data) ? : null; }, 'key check' => function () use ($data) { $result = isset($data[50]) ? $data[50] : null; } ), 100000);

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.4.00.0140.04817.98
7.3.120.0070.05717.49
7.3.110.0030.05817.64
7.3.100.0070.05717.57
7.3.90.0070.04917.70
7.3.80.0060.03217.80
7.3.70.0140.02817.60
7.3.60.0000.03917.45
7.3.50.0070.03217.76
7.3.40.0030.03417.70
7.3.30.0110.02617.79
7.3.20.0030.03020.45
7.3.10.0070.03320.52
7.3.00.0060.03420.53
7.2.250.0000.05317.60
7.2.240.0130.04817.78
7.2.230.0140.06217.73
7.2.220.0070.06817.91
7.2.210.0030.04517.96
7.2.200.0170.03718.09
7.2.190.0100.04117.97
7.2.180.0030.04117.96
7.2.170.0070.04317.80
7.2.130.0080.04220.85
7.2.120.0050.05420.76
7.2.110.0030.04820.70
7.2.100.0060.04220.61
7.2.90.0050.04320.86
7.2.80.0040.05020.70
7.2.70.0070.04721.00
7.2.60.0080.04020.75
7.2.50.0070.05021.00
7.2.40.0070.04420.89
7.2.30.0070.04020.65
7.2.20.0050.03820.79
7.2.10.0030.04620.86
7.2.00.0080.03521.68
7.1.330.0070.09619.78
7.1.320.0030.08319.87
7.1.310.0030.07419.95
7.1.300.0130.07019.89
7.1.290.0030.07919.89
7.1.280.0060.07419.71
7.1.270.0030.08219.73
7.1.260.0030.08619.84
7.1.250.0070.07819.67
7.1.70.0070.06721.25
7.1.60.0030.05921.20
7.1.50.0070.03720.87
7.1.00.0000.12026.37
7.0.200.0030.03520.82
7.0.140.0070.12726.09
7.0.60.0030.07022.98
7.0.50.0200.09321.03
7.0.40.0130.11322.54
7.0.30.0270.07022.68
7.0.20.0300.10322.71
7.0.10.0070.10022.78
7.0.00.0030.07322.78
5.6.280.0070.28335.31
5.6.210.0070.21335.17
5.6.200.0170.19332.57
5.6.190.0100.19734.86
5.6.180.0570.22734.82
5.6.170.0530.22034.71
5.6.160.0030.25334.74
5.6.150.0230.25032.57
5.6.140.0170.19732.54
5.6.130.0170.20332.59
5.6.120.0030.21035.32
5.6.110.0170.23735.49
5.6.100.0230.26735.53
5.6.90.0070.19035.48
5.6.80.0130.19734.71
5.5.350.0230.25734.73
5.5.340.0230.20332.39
5.5.330.0170.25734.57
5.5.320.0430.24034.66
5.5.310.0230.24334.37
5.5.300.0100.21732.45
5.5.290.0130.23732.19
5.5.280.0100.22735.27
5.5.270.0100.26735.02
5.5.260.0100.25035.24
5.5.250.0200.25734.98
5.5.240.0200.26734.67
5.4.450.0230.31733.88
5.4.440.0400.30333.79
5.4.430.0430.30033.84
5.4.420.0430.30733.75
5.4.410.0300.29333.52
5.4.400.0300.27733.44
5.4.390.0200.31733.59
5.4.380.0500.54732.93
5.4.370.0530.30733.16
5.4.360.0870.29332.96
5.4.350.0230.34732.98
5.4.340.0470.30032.96
5.4.320.0110.21726.91
5.4.310.0110.22426.91
5.4.300.0130.21126.91
5.4.290.0110.21626.91
5.4.280.0100.27626.81
5.4.270.0150.27326.80
5.4.260.0100.22126.80
5.4.250.0100.22926.81
5.4.240.0080.22026.80
5.4.230.0080.22526.80
5.4.220.0080.22026.80
5.4.210.0100.21926.80
5.4.200.0050.22326.79
5.4.190.0110.24526.79
5.4.180.0120.24726.79
5.4.170.0040.22826.81
5.4.160.0150.21626.80
5.4.150.0120.22026.80
5.4.140.0100.22426.48
5.4.130.0100.23426.47
5.4.120.0130.21926.43
5.4.110.0150.23126.42
5.4.100.0090.22526.43
5.4.90.0090.23126.42
5.4.80.0090.25226.42
5.4.70.0110.23126.42
5.4.60.0100.23326.42
5.4.50.0120.22326.41
5.4.40.0070.23926.40
5.4.30.0100.24026.40
5.4.20.0110.22426.40
5.4.10.0090.24326.40
5.4.00.0110.25125.88
5.3.290.0100.25426.86
5.3.280.0130.23926.80
5.3.270.0090.24426.81
5.3.260.0050.24226.81
5.3.250.0110.23026.81
5.3.240.0090.27326.81
5.3.230.0110.24126.80
5.3.220.0140.25126.77
5.3.210.0060.27026.77
5.3.200.0070.26526.77
5.3.190.0120.25326.77
5.3.180.0110.29026.77
5.3.170.0080.27126.77
5.3.160.0110.25826.77
5.3.150.0100.25926.77
5.3.140.0110.28626.76
5.3.130.0150.24726.75
5.3.120.0040.26326.75
5.3.110.0080.26126.76
5.3.100.0110.24026.23
5.3.90.0110.22926.22
5.3.80.0130.23726.21
5.3.70.0100.23526.21
5.3.60.0100.23526.20
5.3.50.0070.24326.14
5.3.40.0090.23326.14
5.3.30.0110.23926.11
5.3.20.0080.25025.88
5.3.10.0160.24325.85
5.3.00.0130.24625.83
5.2.170.0040.0329.23
5.2.160.0030.0299.23
5.2.150.0040.0299.23
5.2.140.0010.0369.23
5.2.130.0050.0309.18
5.2.120.0040.0299.18
5.2.110.0040.0299.19
5.2.100.0070.0319.18
5.2.90.0040.0309.18
5.2.80.0030.0349.18
5.2.70.0020.0329.17
5.2.60.0040.0309.13
5.2.50.0050.0319.11
5.2.40.0030.0319.08
5.2.30.0040.0349.05
5.2.20.0010.0319.04
5.2.10.0060.0288.94
5.2.00.0040.0298.81
5.1.60.0050.0228.10
5.1.50.0080.0268.10
5.1.40.0040.0288.07
5.1.30.0050.0308.42
5.1.20.0040.0268.44
5.1.10.0050.0288.17
5.1.00.0060.0288.17
5.0.50.0080.0256.64
5.0.40.0030.0216.52
5.0.30.0030.0376.32
5.0.20.0040.0186.28
5.0.10.0040.0256.27
5.0.00.0070.0286.26
4.4.90.0020.0214.78
4.4.80.0030.0144.76
4.4.70.0060.0164.76
4.4.60.0020.0164.75
4.4.50.0040.0134.77
4.4.40.0010.0274.71
4.4.30.0030.0194.76
4.4.20.0040.0144.84
4.4.10.0010.0214.85
4.4.00.0030.0244.76
4.3.110.0020.0224.67
4.3.100.0030.0204.67
4.3.90.0050.0164.63
4.3.80.0040.0224.59
4.3.70.0000.0174.63
4.3.60.0020.0154.63
4.3.50.0050.0134.63
4.3.40.0000.0264.53
4.3.30.0020.0163.30
4.3.20.0030.0173.28
4.3.10.0010.0163.25
4.3.00.0030.0207.41

preferences:
36.73 ms | 400 KiB | 5 Q