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 = $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.0190.03217.59
7.3.120.0100.05417.90
7.3.110.0130.04917.80
7.3.100.0030.03117.95
7.3.90.0130.04717.68
7.3.80.0070.03017.78
7.3.70.0130.02817.60
7.3.60.0110.02917.76
7.3.50.0060.03417.45
7.3.40.0070.03717.55
7.3.30.0100.03317.73
7.3.20.0030.04520.71
7.3.10.0030.04820.83
7.3.00.0100.03320.60
7.2.250.0110.05917.79
7.2.240.0070.04818.08
7.2.230.0000.04517.85
7.2.220.0070.03717.89
7.2.210.0130.03317.85
7.2.200.0000.04717.98
7.2.190.0070.03717.88
7.2.180.0000.04417.90
7.2.170.0100.05518.02
7.2.00.0030.03622.80
7.1.330.0030.07919.65
7.1.320.0070.07819.86
7.1.310.0070.07719.82
7.1.300.0070.08319.95
7.1.290.0030.07919.75
7.1.280.0030.10019.43
7.1.270.0060.08119.74
7.1.260.0100.07119.98
7.1.70.0060.02920.93
7.1.60.0100.06720.86
7.1.50.0030.04020.71
7.1.00.0100.10726.38
7.0.200.0030.04420.61
7.0.140.0000.13326.00
7.0.60.0070.12322.95
7.0.50.0130.11320.93
7.0.40.0030.08322.68
7.0.30.0400.12322.66
7.0.20.0330.09722.84
7.0.10.0130.11322.77
7.0.00.0070.13322.63
5.6.210.0070.19334.93
5.6.200.0070.24032.52
5.6.190.0170.23334.79
5.6.180.0530.20034.80
5.6.170.0370.20734.82
5.6.160.0170.25034.73
5.6.150.0230.23732.59
5.6.140.0200.23032.52
5.6.130.0130.19732.48
5.6.120.0130.25335.32
5.6.110.0100.21735.49
5.6.100.0130.23335.32
5.6.90.0170.25335.40
5.6.80.0100.18334.91
5.5.350.0170.22334.73
5.5.340.0070.25732.43
5.5.330.0130.25734.55
5.5.320.0300.20034.56
5.5.310.0330.24734.66
5.5.300.0130.25732.36
5.5.290.0130.25732.39
5.5.280.0200.25335.29
5.5.270.0170.25735.19
5.5.260.0170.26035.16
5.5.250.0570.18335.09
5.5.240.0030.23034.56
5.4.450.0300.35733.66
5.4.440.0370.29733.51
5.4.430.0400.29033.79
5.4.420.0230.29033.80
5.4.410.0600.35033.59
5.4.400.0200.30033.48
5.4.390.0200.31733.46
5.4.380.0370.32032.98
5.4.370.0430.29332.92
5.4.360.0530.32733.15
5.4.350.0430.30732.82
5.4.340.0430.34333.13
5.4.320.0130.20526.91
5.4.310.0180.21526.91
5.4.300.0130.21426.91
5.4.290.0110.21826.91
5.4.280.0140.23226.80
5.4.270.0070.21926.80
5.4.260.0120.21526.81
5.4.250.0110.22426.80
5.4.240.0120.21726.79
5.4.230.0110.22226.80
5.4.220.0100.21926.80
5.4.210.0080.20826.80
5.4.200.0150.22326.80
5.4.190.0090.22726.79
5.4.180.0170.22826.80
5.4.170.0100.21526.80
5.4.160.0080.21426.80
5.4.150.0120.21226.79
5.4.140.0080.22426.48
5.4.130.0120.23026.47
5.4.120.0130.23426.43
5.4.110.0090.23326.42
5.4.100.0120.27426.43
5.4.90.0090.23526.41
5.4.80.0130.22026.42
5.4.70.0090.23926.42
5.4.60.0120.24426.41
5.4.50.0150.22226.41
5.4.40.0130.24526.40
5.4.30.0150.23426.40
5.4.20.0110.23426.40
5.4.10.0150.22626.38
5.4.00.0150.21625.89
5.3.290.0130.23626.87
5.3.280.0130.24326.79
5.3.270.0120.27126.80
5.3.260.0100.24826.81
5.3.250.0090.23026.81
5.3.240.0080.26026.81
5.3.230.0130.23026.80
5.3.220.0110.24926.77
5.3.210.0060.28026.77
5.3.200.0100.25026.77
5.3.190.0140.26626.77
5.3.180.0130.27426.77
5.3.170.0100.26926.77
5.3.160.0090.25126.77
5.3.150.0110.25026.77
5.3.140.0070.26126.76
5.3.130.0130.25626.75
5.3.120.0100.25226.76
5.3.110.0130.23426.76
5.3.100.0140.24226.24
5.3.90.0110.24426.22
5.3.80.0080.26926.21
5.3.70.0180.38826.21
5.3.60.0100.30026.20
5.3.50.0150.27826.14
5.3.40.0100.26826.14
5.3.30.0150.33926.11
5.3.20.0180.26825.88
5.3.10.0110.25925.85
5.3.00.0080.24225.83
5.2.170.0050.0419.23
5.2.160.0020.0319.22
5.2.150.0050.0319.23
5.2.140.0040.0319.22
5.2.130.0030.0319.18
5.2.120.0030.0299.19
5.2.110.0070.0299.19
5.2.100.0040.0299.18
5.2.90.0040.0289.18
5.2.80.0040.0309.18
5.2.70.0060.0289.18
5.2.60.0050.0309.14
5.2.50.0040.0309.11
5.2.40.0060.0279.08
5.2.30.0050.0299.05
5.2.20.0040.0299.04
5.2.10.0060.0318.95
5.2.00.0060.0358.81
5.1.60.0020.0268.10
5.1.50.0060.0268.09
5.1.40.0030.0258.07
5.1.30.0030.0278.42
5.1.20.0020.0278.44
5.1.10.0050.0258.17
5.1.00.0060.0238.17
5.0.50.0090.0216.65
5.0.40.0030.0196.52
5.0.30.0030.0326.32
5.0.20.0020.0216.28
5.0.10.0010.0236.27
5.0.00.0040.0316.26
4.4.90.0060.0134.78
4.4.80.0040.0144.76
4.4.70.0020.0174.76
4.4.60.0020.0164.75
4.4.50.0020.0174.77
4.4.40.0040.0244.71
4.4.30.0040.0154.76
4.4.20.0020.0164.84
4.4.10.0040.0184.85
4.4.00.0020.0264.76
4.3.110.0030.0154.67
4.3.100.0020.0154.67
4.3.90.0060.0114.64
4.3.80.0030.0244.59
4.3.70.0060.0114.63
4.3.60.0020.0154.63
4.3.50.0020.0154.63
4.3.40.0010.0254.54
4.3.30.0010.0163.30
4.3.20.0010.0173.28
4.3.10.0020.0153.24
4.3.00.0070.0236.63

preferences:
43.87 ms | 401 KiB | 5 Q