3v4l.org

run code in 300+ PHP versions simultaneously
<?php 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 = 2; 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.10.0060.01214.88
7.4.00.0110.00614.96
7.3.130.0150.00414.82
7.3.120.0060.01215.13
7.3.110.0090.00714.95
7.3.100.0080.00514.75
7.3.90.0030.00914.97
7.3.80.0070.00714.66
7.3.70.0090.00614.85
7.3.60.0060.00914.84
7.3.50.0070.00814.78
7.3.40.0080.00614.92
7.3.30.0080.00414.91
7.3.20.0120.00216.76
7.3.10.0030.01116.48
7.3.00.0020.00916.72
7.2.260.0110.00415.30
7.2.250.0060.01314.88
7.2.240.0020.01714.92
7.2.230.0030.01015.17
7.2.220.0080.00715.13
7.2.210.0030.01114.94
7.2.200.0070.00515.11
7.2.190.0050.01014.98
7.2.180.0070.00615.00
7.2.170.0040.00715.08
7.2.160.0060.00815.03
7.2.150.0070.00917.03
7.2.140.0060.00816.95
7.2.130.0020.01217.06
7.2.120.0040.01316.88
7.2.110.0050.00917.03
7.2.100.0020.01416.85
7.2.90.0080.00817.05
7.2.80.0030.01316.89
7.2.70.0110.00516.87
7.2.60.0050.01016.93
7.2.50.0080.00316.88
7.2.40.0020.01217.02
7.2.30.0070.00617.07
7.2.20.0050.00816.97
7.2.10.0030.00917.09
7.2.00.0020.01017.75
7.1.330.0020.01315.81
7.1.320.0040.00815.92
7.1.310.0050.00515.83
7.1.300.0080.00615.83
7.1.290.0050.01115.67
7.1.280.0020.01115.66
7.1.270.0030.01115.84
7.1.260.0050.01115.78
7.1.250.0100.00515.72
7.1.240.0040.00815.66
7.1.230.0070.00415.51
7.1.220.0140.00015.66
7.1.210.0060.00615.61
7.1.200.0000.01315.76
7.1.190.0040.01415.79
7.1.180.0040.00815.79
7.1.170.0040.00815.69
7.1.160.0030.00615.70
7.1.150.0030.01215.86
7.1.140.0030.01015.74
7.1.130.0090.00015.60
7.1.120.0030.00915.89
7.1.110.0000.00915.84
7.1.100.0070.00715.78
7.1.90.0080.00815.88
7.1.80.0090.00615.79
7.1.70.0020.01116.33
7.1.60.0100.00817.71
7.1.50.0110.00925.40
7.1.40.0110.00415.82
7.1.30.0060.00915.61
7.1.20.0030.01015.61
7.1.10.0070.00715.66
7.1.00.0050.04318.96
7.0.330.0100.00615.48
7.0.320.0080.00815.44
7.0.310.0110.00415.12
7.0.300.0040.00715.53
7.0.290.0040.00815.45
7.0.280.0060.00615.30
7.0.270.0130.00315.24
7.0.260.0120.00315.24
7.0.250.0030.00715.50
7.0.240.0100.00315.38
7.0.230.0040.01115.59
7.0.220.0030.00615.47
7.0.210.0040.01115.19
7.0.200.0060.00816.03
7.0.190.0130.00315.22
7.0.180.0000.01515.49
7.0.170.0030.00615.59
7.0.160.0060.00615.47
7.0.150.0040.01115.53
7.0.140.0060.04018.64
7.0.130.0030.00915.29
7.0.120.0030.01215.55
7.0.110.0060.00815.54
7.0.100.0100.00615.25
7.0.90.0070.01015.60
7.0.80.0030.00815.54
7.0.70.0070.00415.57
7.0.60.0070.03417.73
7.0.50.0050.04416.64
7.0.40.0080.04316.87
7.0.30.0160.03016.90
7.0.20.0150.03016.84
7.0.10.0170.04216.73
7.0.00.0020.03216.82
5.6.400.0070.00714.44
5.6.390.0090.00614.72
5.6.380.0030.01414.61
5.6.370.0040.01214.64
5.6.360.0000.01214.26
5.6.350.0040.01114.63
5.6.340.0000.01114.54
5.6.330.0030.01514.52
5.6.320.0000.01214.75
5.6.310.0060.00914.02
5.6.300.0040.01214.70
5.6.290.0080.00614.34
5.6.280.0090.03717.64
5.6.270.0030.01214.20
5.6.260.0040.01414.45
5.6.250.0040.01114.19
5.6.240.0090.00614.47
5.6.230.0090.00914.71
5.6.220.0030.01314.66
5.6.210.0110.04117.57
5.6.200.0080.02516.31
5.6.190.0020.03317.68
5.6.180.1510.02217.54
5.6.170.0070.03017.39
5.6.160.0120.03817.51
5.6.150.0070.02316.46
5.6.140.0150.03416.48
5.6.130.0020.05216.30
5.6.120.0100.04217.69
5.6.110.0120.03517.88
5.6.100.0000.03117.72
5.6.90.0080.04917.58
5.6.80.0090.04217.49
5.6.70.0030.00914.60
5.6.60.0060.00914.33
5.6.50.0030.01014.05
5.6.40.0040.01114.57
5.6.30.0070.00714.26
5.6.20.0030.01214.46
5.6.10.0120.00314.47
5.6.00.0060.00914.45
5.5.380.0120.00614.55
5.5.370.0090.00614.68
5.5.360.0070.01014.32
5.5.350.0130.04217.41
5.5.340.0080.04716.23
5.5.330.0030.05217.29
5.5.320.0220.02317.40
5.5.310.0200.02117.27
5.5.300.0050.04416.24
5.5.290.0050.03116.29
5.5.280.0080.04617.68
5.5.270.0030.04917.65
5.5.260.0050.04717.44
5.5.250.0080.04817.46
5.5.240.0130.02517.33
5.5.230.0060.00914.19
5.5.220.0090.00314.30
5.5.210.0060.00914.45
5.5.200.0030.01314.35
5.5.190.0030.01314.54
5.5.180.0080.00814.40
5.5.170.0130.00014.59
5.5.160.0030.01314.47
5.5.150.0070.00314.54
5.5.140.0040.01514.19
5.5.130.0060.00614.53
5.5.120.0040.00714.30
5.5.110.0060.00614.52
5.5.100.0030.01214.62
5.5.90.0030.01214.25
5.5.80.0080.00814.32
5.5.70.0000.01414.31
5.5.60.0030.01014.24
5.5.50.0060.00914.38
5.5.40.0040.01414.67
5.5.30.0030.00613.95
5.5.20.0120.00314.57
5.5.10.0050.00514.53
5.5.00.0120.00314.39
5.4.450.0290.03815.33
5.4.440.0150.02515.44
5.4.430.0150.03515.25
5.4.420.0200.03515.46
5.4.410.0130.02615.30
5.4.400.0110.04415.03
5.4.390.2010.01815.02
5.4.380.0120.02615.08
5.4.370.0220.03815.26
5.4.360.0200.03315.05
5.4.350.0130.02315.08
5.4.340.0050.02315.32
5.4.330.0050.00511.07
5.4.320.0130.02415.09
5.4.310.0150.02915.13
5.4.300.0210.03015.21
5.4.290.0050.02211.85
5.4.280.0040.02511.67
5.4.270.0050.02311.88
5.4.260.0040.03211.74
5.4.250.0060.02411.96
5.4.240.0020.02411.79
5.4.230.0100.02411.81
5.4.220.0110.02811.92
5.4.210.0080.02511.78
5.4.200.0050.02611.79
5.4.190.0040.02411.81
5.4.180.0070.02211.65
5.4.170.0070.02011.85
5.4.160.0070.01911.79
5.4.150.0040.02411.78
5.4.140.0040.02511.54
5.4.130.0060.02211.61
5.4.120.0040.02311.69
5.4.110.0090.02111.75
5.4.100.0050.02211.71
5.4.90.0050.02411.48
5.4.80.0020.02611.66
5.4.70.0060.02111.66
5.4.60.0060.02211.63
5.4.50.0090.02111.62
5.4.40.0040.02311.51
5.4.30.0070.02011.65
5.4.20.0050.02211.50
5.4.10.0070.02011.48
5.4.00.0050.02411.34
5.3.290.1970.02213.40
5.3.280.0080.02211.71
5.3.270.0050.02411.71
5.3.260.0050.02411.65
5.3.250.0040.02211.82
5.3.240.0060.02511.53
5.3.230.0060.02411.70
5.3.220.0060.02211.57
5.3.210.0060.02511.66
5.3.200.0040.02411.68
5.3.190.0050.02511.71
5.3.180.0070.02011.60
5.3.170.0020.02711.72
5.3.160.0070.02411.75
5.3.150.0060.02711.72
5.3.140.0080.02211.56
5.3.130.0090.03011.75
5.3.120.0080.03111.77
5.3.110.0060.02811.74
5.3.100.0040.02111.46
5.3.90.0100.01911.53
5.3.80.0030.02311.38
5.3.70.0070.02011.40
5.3.60.0070.02311.43
5.3.50.0050.02411.39
5.3.40.0060.02311.36
5.3.30.0060.02311.26
5.3.20.0040.02311.25
5.3.10.0070.02111.02
5.3.00.0050.02111.12
5.2.170.0070.0329.29
5.2.160.0060.0299.29
5.2.150.0060.0349.30
5.2.140.0050.0439.29
5.2.130.0050.0349.25
5.2.120.0040.0419.25
5.2.110.0060.0349.26
5.2.100.0050.0299.26
5.2.90.0070.0289.25
5.2.80.0070.0289.25
5.2.70.0030.0349.25
5.2.60.0100.0389.20
5.2.50.0020.0459.17
5.2.40.0060.0299.14
5.2.30.0030.0339.13
5.2.20.0030.0329.11
5.2.10.0100.0309.02
5.2.00.0060.0438.87
5.1.60.0080.0348.16
5.1.50.0050.0368.15
5.1.40.0060.0258.14
5.1.30.0070.0248.49
5.1.20.0060.0278.52
5.1.10.0080.0368.24
5.1.00.0110.0408.24
5.0.50.0060.0326.72
5.0.40.0060.0316.58
5.0.30.0050.0456.39
5.0.20.0040.0296.37
5.0.10.0050.0316.34
5.0.00.0050.0476.34
4.4.90.0070.0224.78
4.4.80.0040.0284.76
4.4.70.0040.0244.75
4.4.60.0030.0184.75
4.4.50.0020.0204.77
4.4.40.0060.0264.73
4.4.30.0060.0214.75
4.4.20.0050.0184.84
4.4.10.0020.0184.85
4.4.00.0040.0254.76
4.3.110.0030.0174.67
4.3.100.0030.0174.67
4.3.90.0030.0184.67
4.3.80.0040.0254.66
4.3.70.0060.0144.66
4.3.60.0030.0174.66
4.3.50.0030.0184.66
4.3.40.0020.0264.62
4.3.30.0030.0203.43
4.3.20.0020.0183.41
4.3.10.0030.0173.35
4.3.00.0100.02013.91

preferences:
79 ms | 401 KiB | 5 Q