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, 10000, 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, 1000000); benchmark(array( 'count()' => function () use ($data) { $result = count($data) == 0; }, 'empty()' => function () use ($data) { $result = empty($data); } ), 1000000); 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; } ), 1000000);

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.0070.28651.47
7.1.70.0170.32349.16
7.1.60.0130.31248.95
7.1.50.0100.24948.79
7.1.00.0070.36354.34
7.0.200.0070.36348.73
7.0.140.0070.47353.92
7.0.60.0170.37050.77
7.0.50.0200.32748.54
7.0.40.0130.32750.26
7.0.30.0630.32050.39
7.0.20.0930.44350.26
7.0.10.1030.36750.36
7.0.00.0270.37750.22
5.6.280.0730.57384.43
5.6.210.0930.57384.13
5.6.200.0630.55081.77
5.6.190.0730.53383.91
5.6.180.0930.50083.79
5.6.170.1170.55383.90
5.6.160.0870.57383.88
5.6.150.0770.58781.72
5.6.140.0800.53781.70
5.6.130.0230.51082.40
5.6.120.0630.58384.56
5.6.110.0730.55384.55
5.6.100.0600.60084.68
5.6.90.0900.58084.57
5.6.80.0800.53383.95
5.6.70.2870.48384.05
5.5.350.0870.57383.96
5.5.340.0770.57381.57
5.5.330.0670.59783.73
5.5.320.1100.56783.61
5.5.310.0930.57083.80
5.5.300.0600.55781.50
5.5.290.0570.54781.56
5.5.280.0870.53084.37
5.5.270.0800.52784.34
5.5.260.1000.53084.31
5.5.250.0470.52384.25
5.5.240.2700.55383.84
5.4.450.2100.73783.13
5.4.440.1500.78783.09
5.4.430.1300.76383.08
5.4.420.1670.77782.84
5.4.410.1830.72083.05
5.4.400.1500.77382.34
5.4.390.1970.74782.34
5.4.380.1700.85782.38
5.4.370.2401.05082.57
5.4.360.1770.88382.54
5.4.350.2200.85082.55
5.4.340.2330.89082.57
5.4.320.0730.58476.33
5.4.310.0640.59876.33
5.4.300.0880.56176.33
5.4.290.0600.57476.32
5.4.280.0730.60676.22
5.4.270.0930.57076.22
5.4.260.0840.59776.22
5.4.250.0880.58976.22
5.4.240.0860.61376.22
5.4.230.0830.61076.21
5.4.220.0780.60776.21
5.4.210.0830.57176.21
5.4.200.0210.56776.81
5.4.190.0820.59476.21
5.4.180.0790.58276.21
5.4.170.0700.59976.23
5.4.160.0770.60476.21
5.4.150.0970.57576.21
5.4.140.0830.61375.89
5.4.130.0820.60175.88
5.4.120.0240.59976.44
5.4.110.0770.59975.84
5.4.100.0620.61475.84
5.4.90.0790.59575.84
5.4.80.0760.59875.84
5.4.70.0920.57975.84
5.4.60.0850.61575.84
5.4.50.0970.59575.83
5.4.40.0840.60775.82
5.4.30.0910.59775.82
5.4.20.0830.63275.82
5.4.10.0650.60375.82
5.4.00.0840.62475.31
5.3.290.1400.58976.12
5.3.280.1160.59976.05
5.3.270.1050.62076.06
5.3.260.1070.60676.07
5.3.250.1060.62676.07
5.3.240.1180.65476.06
5.3.230.0980.59576.06
5.3.220.1080.61776.02
5.3.210.0970.61976.03
5.3.200.1130.64876.02
5.3.190.1020.65376.03
5.3.180.0260.58976.63
5.3.170.1100.60376.02
5.3.160.0840.59376.02
5.3.150.1030.59776.02
5.3.140.0990.58876.01
5.3.130.1080.59576.00
5.3.120.1000.60276.01
5.3.110.0980.61276.00
5.3.100.1040.61475.49
5.3.90.1110.62175.47
5.3.80.1030.60175.47
5.3.70.1130.62975.46
5.3.60.1040.62775.45
5.3.50.1240.57075.40
5.3.40.0950.61275.40
5.3.30.1120.63575.36
5.3.20.1100.66575.14
5.3.10.1030.62775.10
5.3.00.1230.67875.09
5.2.170.0080.0359.23
5.2.160.0060.0309.23
5.2.150.0070.0389.23
5.2.140.0070.0319.22
5.2.130.0060.0319.19
5.2.120.0060.0329.18
5.2.110.0040.0309.18
5.2.100.0060.0389.17
5.2.90.0050.0329.18
5.2.80.0060.0399.17
5.2.70.0050.0319.18
5.2.60.0080.0289.13
5.2.50.0070.0299.11
5.2.40.0030.0319.08
5.2.30.0060.0299.05
5.2.20.0080.0339.04
5.2.10.0050.0298.94
5.2.00.0060.0378.81
5.1.60.0050.0278.10
5.1.50.0080.0238.09
5.1.40.0030.0278.07
5.1.30.0050.0268.42
5.1.20.0050.0268.44
5.1.10.0050.0268.17
5.1.00.0040.0298.17
5.0.50.0050.0226.64
5.0.40.0040.0196.51
5.0.30.0020.0356.32
5.0.20.0050.0196.28
5.0.10.0020.0226.27
5.0.00.0050.0316.26
4.4.90.0010.0184.78
4.4.80.0040.0154.75
4.4.70.0050.0184.76
4.4.60.0030.0164.76
4.4.50.0040.0154.77
4.4.40.0020.0274.71
4.4.30.0030.0164.76
4.4.20.0050.0144.84
4.4.10.0050.0144.85
4.4.00.0030.0254.76
4.3.110.0050.0144.67
4.3.100.0040.0144.66
4.3.90.0050.0154.63
4.3.80.0040.0244.58
4.3.70.0040.0134.63
4.3.60.0030.0154.63
4.3.50.0060.0124.62
4.3.40.0020.0294.53
4.3.30.0020.0163.30
4.3.20.0030.0153.28
4.3.10.0030.0203.25
4.3.00.0000.0237.41

preferences:
35.08 ms | 400 KiB | 5 Q