3v4l.org

run code in 300+ PHP versions simultaneously
<?php ini_set('memory_limit', '512M'); function test_in_array($a) { $valid = array('a', 'b', 'c', 'd'); if (in_array($a, $valid)) { return true; } return false; } function test_array_flip_isset($a) { $valid = array('a', 'b', 'c', 'd'); $valid = array_flip($valid); if (isset($valid[$a])) { return true; } return false; } function test_isset($a) { $valid = array('a' => true, 'b' => true, 'c' => true, 'd' => true); if (isset($valid[$a])) { return true; } return false; } function test_empty($a) { $valid = array('a' => true, 'b' => true, 'c' => true, 'd' => true); if (empty($valid[$a])) { return false; } return true; } function test_not_empty($a) { $valid = array('a' => true, 'b' => true, 'c' => true, 'd' => true); if (!empty($valid[$a])) { return true; } return false; } function test_array_key_exists($a) { $valid = array('a' => true, 'b' => true, 'c' => true, 'd' => true); if (array_key_exists($a, $valid)) { return true; } return false; } function test_switch($a) { switch ($a) { case 'a': case 'b': case 'c': case 'd': return true; default: // do nothing break; } return false; } function test_equals($a) { if (($a == 'a') || ($a == 'b') || ($a == 'c') || ($a == 'd')) { return true; } return false; } function test_same($a) { if (($a === 'a') || ($a === 'b') || ($a === 'c') || ($a === 'd')) { return true; } return false; } $randomValues = array(); $exp = 4; for ($i = 0; $i < pow(10, $exp); $i++) { $randomValues[] = chr(mt_rand(65, 132)); } echo '<strong>10^' . $exp . ' random letters</strong><br/><br/>'; $functions = array( 'test_switch', 'test_in_array', 'test_array_flip_isset', 'test_isset', 'test_empty', 'test_not_empty', 'test_array_key_exists', 'test_equals', 'test_same', ); $baseline = null; foreach ($functions as $func) { $start = microtime(true); foreach ($randomValues as $value) { $func($value); } $end = microtime(true); if ($baseline === null) { echo $func . ': ' . number_format($end - $start, 2) . ' s<br/>'; } else { echo $func . ': ' . number_format($end - $start, 2) . ' s ' . number_format(($end - $start) / $baseline * 100, 2) . '% <br/>'; } if ($func == 'test_switch') { $baseline = $end - $start; } }

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.0100.02715.36
7.3.120.0070.03014.91
7.3.110.0100.02615.21
7.3.100.0090.01515.13
7.3.90.0070.02015.44
7.3.80.0070.02015.43
7.3.70.0000.02815.23
7.3.60.0070.02315.17
7.3.50.0090.01615.32
7.3.40.0040.02515.10
7.3.30.0090.01515.20
7.3.20.0030.02416.41
7.3.10.0100.01916.82
7.3.00.0070.02316.66
7.2.250.0030.03415.41
7.2.240.0070.03415.64
7.2.230.0060.02215.19
7.2.220.0130.01315.46
7.2.210.0030.02615.22
7.2.200.0070.02415.39
7.2.190.0090.01915.59
7.2.180.0060.02215.56
7.2.170.0030.02415.49
7.1.330.0030.03615.90
7.1.320.0070.03015.64
7.1.310.0090.02515.93
7.1.300.0160.02215.67
7.1.290.0000.03815.96
7.1.280.0030.03615.64
7.1.270.0000.03715.72
7.1.260.0060.03216.06
7.1.70.0090.01517.02
7.1.60.0070.03719.46
7.1.50.0100.01934.86
7.1.00.0030.09022.36
7.0.200.0060.03216.71
7.0.140.0070.09322.10
7.0.60.0070.10320.74
7.0.50.0030.06018.71
7.0.40.0070.07320.22
7.0.30.0270.08320.30
7.0.20.0330.07720.24
7.0.10.0230.06720.24
7.0.00.0100.06720.07
5.6.280.0100.13322.59
5.6.210.0000.11722.11
5.6.200.0270.08019.71
5.6.190.0170.13021.80
5.6.180.3270.07322.06
5.6.170.0270.08322.03
5.6.160.0100.10322.00
5.6.150.0030.11319.72
5.6.140.0200.13019.56
5.6.130.0130.13019.68
5.6.120.0070.09322.55
5.6.110.0200.12322.69
5.6.100.0170.13022.58
5.6.90.0030.13322.54
5.6.80.0070.13722.04
5.6.70.0070.14021.95
5.5.350.0130.13721.95
5.5.340.0030.08719.47
5.5.330.0130.08021.86
5.5.320.0500.12321.77
5.5.310.0300.09021.75
5.5.300.0070.08319.47
5.5.290.0030.14019.52
5.5.280.0030.08322.41
5.5.270.0130.13022.34
5.5.260.0030.14322.44
5.5.250.0030.11322.36
5.5.240.0200.11721.62
5.4.450.0630.10320.94
5.4.440.0270.07020.93
5.4.430.0200.11320.77
5.4.420.0270.12021.18
5.4.410.0200.11020.82
5.4.400.0300.10020.63
5.4.390.4000.11020.62
5.4.380.0230.07720.59
5.4.370.0300.12020.83
5.4.360.0370.10720.64
5.4.350.0230.07720.45
5.4.340.0170.07320.60
5.4.320.0230.09020.55
5.4.310.0330.07320.58
5.4.300.0230.12320.58
5.4.290.0080.09814.05
5.4.280.0110.08713.95
5.4.270.0110.09413.94
5.4.260.0060.09413.95
5.4.250.0100.10013.94
5.4.240.0070.08713.95
5.4.230.0050.09513.93
5.4.220.0060.09313.93
5.4.210.0080.09313.94
5.4.200.0050.09713.93
5.4.190.0050.09013.93
5.4.180.0060.09113.93
5.4.170.0080.10413.94
5.4.160.0020.09313.94
5.4.150.0090.08113.94
5.4.140.0070.08313.62
5.4.130.0110.09113.61
5.4.120.0060.13513.57
5.4.110.0070.12513.57
5.4.100.0070.09513.56
5.4.90.0070.11213.56
5.4.80.0080.09313.56
5.4.70.0040.08913.55
5.4.60.0060.10013.56
5.4.50.0050.09913.56
5.4.40.0060.10713.55
5.4.30.0070.08313.54
5.4.20.0060.09713.54
5.4.10.0080.07713.54
5.4.00.0080.08513.03
5.3.290.3570.07716.24
5.3.280.0080.10114.39
5.3.270.0060.10214.40
5.3.260.0070.08914.41
5.3.250.0080.09614.41
5.3.240.0070.09814.41
5.3.230.0090.09414.40
5.3.220.0050.15614.36
5.3.210.0050.11914.37
5.3.200.0110.08914.36
5.3.190.0090.09114.37
5.3.180.0160.12814.36
5.3.170.0140.14314.36
5.3.160.0040.12714.36
5.3.150.0040.10614.36
5.3.140.0100.14514.35
5.3.130.0090.09014.35
5.3.120.0080.10314.35
5.3.110.0100.15214.35
5.3.100.0090.13713.84
5.3.90.0120.12813.82
5.3.80.0080.13313.81
5.3.70.0120.12913.80
5.3.60.0060.09213.79
5.3.50.0120.13813.73
5.3.40.0100.14413.73
5.3.30.0070.13913.70
5.3.20.0110.08813.48
5.3.10.0040.09213.44
5.3.00.0090.10013.42
5.2.170.0090.09910.88
5.2.160.0030.09510.88
5.2.150.0070.13210.88
5.2.140.0090.16310.87
5.2.130.0120.20210.83
5.2.120.0160.14710.83
5.2.110.0090.11610.84
5.2.100.0080.10010.83
5.2.90.0080.12810.90
5.2.80.0140.15710.82
5.2.70.0070.14610.82
5.2.60.0060.10610.77
5.2.50.0050.10210.75
5.2.40.0040.09410.72
5.2.30.0080.11210.78
5.2.20.0080.09710.58
5.2.10.0070.09710.48
5.2.00.0030.12010.33
5.1.60.0070.10110.27
5.1.50.0080.16310.27
5.1.40.0090.16910.25
5.1.30.0100.15610.60
5.1.20.0070.19210.63
5.1.10.0100.12810.35
5.1.00.0070.16010.35
5.0.50.0080.2588.83
5.0.40.0060.2108.69
5.0.30.0050.1668.51
5.0.20.0040.1368.48
5.0.10.0030.1418.46
5.0.00.0050.1688.45
4.4.90.0040.1356.85
4.4.80.0040.1456.96
4.4.70.0050.1316.82
4.4.60.0060.1656.82
4.4.50.0080.1986.84
4.4.40.0060.2096.83
4.4.30.0050.1386.83
4.4.20.0050.1326.89
4.4.10.0030.2016.89
4.4.00.0050.2096.87
4.3.110.0060.1516.77
4.3.100.0050.1786.75
4.3.90.0050.1606.78
4.3.80.0070.2516.88
4.3.70.0050.2156.77
4.3.60.0080.1546.77
4.3.50.0040.1506.88
4.3.40.0030.1526.83
4.3.30.0020.1585.64
4.3.20.0030.1685.62
4.3.10.0050.2185.57
4.3.00.0070.17013.91

preferences:
37.15 ms | 400 KiB | 5 Q