3v4l.org

run code in 300+ PHP versions simultaneously
<?php //copyright Lawrence Truett and FluffyCat.com 2009, all rights reserved define('BR', "\n"); echo 'Performance Testing PHP if / else VS switch with 100,000 iterations'.BR.BR; $ifTime = 0; $switchTime = 0; $arrayTime = 0; for ($x = 0; $x < 100000; $x++) { $oneToFive = rand(1,5); if (0 == fmod($x,2)) { $switchTime = $switchTime + testSwitch($oneToFive); $arrayTime = $arrayTime + testArray($oneToFive); $ifTime = $ifTime + testIf($oneToFive); } else { $ifTime = $ifTime + testArray($oneToFive); $arrayTime = $arrayTime + testArray($oneToFive); $switchTime = $switchTime + testIf($oneToFive); } } echo 'total if / else time: '.$ifTime.BR; echo 'total case time: '.$switchTime.BR; echo 'total array time: '.$arrayTime.BR; echo BR; if ($ifTime > $switchTime) { echo 'switch is quicker by '.($ifTime - $switchTime).BR; } else { echo 'if / else is quicker by '.($switchTime - $ifTime).BR; } function testSwitch($oneToFive) { $time_start = microtime(true); switch($oneToFive) { case 1: $z = 1; break; case 2: $z = 2; break; case 3: $z = 3; break; case 4: $z = 4; break; case 5: $z = 5; break; } $time_end = microtime(true); $time = $time_end - $time_start; return $time; } function testIf($oneToFive) { $time_start = microtime(true); if (1 == $oneToFive) { $z = 1; } elseif(2 == $oneToFive) { $z = 2; } elseif(3 == $oneToFive) { $z = 3; } elseif(4 == $oneToFive) { $z = 4; } elseif(5 == $oneToFive) { $z = 5; } $time_end = microtime(true); $time = $time_end - $time_start; return $time; } function testArray($oneToFive){ $time_start = microtime(true); $array = array(0,1,2,3,4,5); $result = $array[$oneToFive]; $time_end = microtime(true); $time = $time_end - $time_start; return $time; }

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.3.60.0130.06815.07
7.3.50.0060.06714.77
7.3.40.0080.06714.98
7.3.30.0060.06514.84
7.3.20.0130.06516.75
7.3.10.0110.05716.76
7.3.00.0100.05816.80
7.2.190.0080.06715.19
7.2.180.0080.06615.24
7.2.170.0110.06415.19
7.2.160.0080.05715.33
7.2.150.0120.06517.11
7.2.140.0080.08017.10
7.2.130.0090.06717.04
7.2.120.0050.07916.93
7.2.110.0050.07917.04
7.2.100.0100.07117.12
7.2.90.0110.07717.17
7.2.80.0110.06717.20
7.2.70.0050.09817.06
7.2.60.0110.06717.04
7.2.50.0100.07517.16
7.2.40.0080.07917.07
7.2.30.0060.07917.14
7.2.20.0100.07117.07
7.2.10.0050.06717.09
7.2.00.0100.06917.12
7.1.300.0100.09016.00
7.1.290.0050.08515.98
7.1.280.0030.08515.77
7.1.270.0090.08215.96
7.1.260.0070.12315.88
7.1.250.0080.07915.98
7.1.240.0100.07515.98
7.1.230.0120.09015.96
7.1.220.0090.08416.00
7.1.210.0030.12616.10
7.1.200.0070.08416.09
7.1.190.0030.10515.91
7.1.180.0030.11215.90
7.1.170.0070.09416.13
7.1.160.0150.10715.93
7.1.150.0130.09516.05
7.1.140.0060.09015.89
7.1.130.0130.12815.87
7.1.120.0000.08515.93
7.1.110.0090.09215.95
7.1.100.0060.09816.01
7.1.90.0160.08316.08
7.1.80.0060.08016.01
7.1.70.0030.08715.90
7.1.60.0130.08915.89
7.1.50.0030.12915.75
7.1.40.0100.08615.94
7.1.30.0060.08615.58
7.1.20.0060.11716.05
7.1.10.0000.09315.95
7.1.00.0030.08015.99
7.0.330.0030.10115.69
7.0.320.0140.10615.46
7.0.310.0100.10515.39
7.0.300.0040.10515.37
7.0.290.0130.10215.51
7.0.280.0160.11115.31
7.0.270.0070.14215.42
7.0.260.0100.13015.39
7.0.250.0130.12715.51
7.0.240.0150.13115.73
7.0.230.0070.11115.23
7.0.220.0190.08815.75
7.0.210.0100.10115.60
7.0.200.0190.12115.63
7.0.190.0040.11215.53
7.0.180.0210.10115.69
7.0.170.0170.10115.37
7.0.160.0130.09215.40
7.0.150.0070.09315.68
7.0.140.0160.10315.63
7.0.130.0070.11115.48
7.0.120.0040.10415.45
7.0.110.0140.09715.39
7.0.100.0070.09415.67
7.0.90.0100.13415.30
7.0.80.0040.09115.46
7.0.70.0250.09615.49
7.0.60.0130.15915.76
7.0.50.0160.09015.79
7.0.40.0100.10015.76
7.0.30.0240.07915.50
7.0.20.0180.08313.94
7.0.10.0150.09213.93
7.0.00.0230.08513.89
5.6.400.0000.22814.71
5.6.390.0100.19214.39
5.6.380.0030.18714.20
5.6.370.0240.20614.74
5.6.360.0150.20714.43
5.6.350.0130.18814.41
5.6.340.0190.28514.21
5.6.330.0160.25614.33
5.6.320.0070.30414.60
5.6.310.0100.20514.38
5.6.300.0200.19314.39
5.6.290.0190.17714.53
5.6.280.0070.18614.53
5.6.270.0100.19114.48
5.6.260.0130.20814.50
5.6.250.0200.18914.56
5.6.240.0230.18214.42
5.6.230.0130.20114.27
5.6.220.0070.24714.54
5.6.210.0120.20514.58
5.6.200.0130.19114.75
5.6.190.0130.18414.61
5.6.180.0160.19814.57
5.6.170.0030.27514.39
5.6.160.0130.18814.70
5.6.150.0190.20014.57
5.6.140.0230.24614.59
5.6.130.0100.20014.47
5.6.120.0000.20514.74
5.6.110.0160.18814.52
5.6.100.0130.22014.45
5.6.90.0130.20614.57
5.6.80.0130.19214.29
5.6.70.0160.21214.52
5.6.60.0130.20614.38
5.6.50.0230.18214.71
5.6.40.0100.20714.22
5.6.30.0130.20214.43
5.6.20.0100.18614.41
5.6.10.0130.21814.58
5.6.00.0030.29414.67
5.5.380.0230.27214.17
5.5.370.0320.22514.35
5.5.360.0130.22814.21
5.5.350.0160.19314.32
5.5.340.0190.19514.54
5.5.330.0190.21614.54
5.5.320.0290.20214.34
5.5.310.0230.19914.63
5.5.300.0160.28614.17
5.5.290.0130.20114.63
5.5.280.0230.18414.59
5.5.270.0190.19214.64
5.5.260.0200.23414.42
5.5.250.0250.19214.11
5.5.240.0100.28814.61
5.5.230.0130.22314.37
5.5.220.0160.23214.44
5.5.210.0190.19814.39
5.5.200.0100.20314.64
5.5.190.0160.19414.28
5.5.180.0130.19014.40
5.5.170.0160.21414.39
5.5.160.0100.24714.26
5.5.150.0230.20914.49
5.5.140.0160.25614.56
5.5.130.0220.19914.56
5.5.120.0100.20214.65
5.5.110.0130.20014.33
5.5.100.0030.30514.25
5.5.90.0070.19614.23
5.5.80.0070.22314.55
5.5.70.0190.23314.62
5.5.60.0160.24414.16
5.5.50.0100.18314.34
5.5.40.0070.19714.44
5.5.30.0250.20914.13
5.5.20.0070.28114.55
5.5.10.0070.33213.98
5.5.00.0130.27813.99
5.4.450.0150.23611.25
5.4.440.0130.24711.42
5.4.430.0120.20011.33
5.4.420.0130.19411.32
5.4.410.0070.19111.26
5.4.400.0100.19111.22
5.4.390.0060.19311.02
5.4.380.0030.28411.15
5.4.370.0070.18911.38
5.4.360.0190.19211.10
5.4.350.0130.32211.10
5.4.340.0100.20711.20
5.4.330.0100.29811.22
5.4.320.0120.28110.96
5.4.310.0100.18411.18
5.4.300.0030.21710.91
5.4.290.0130.20010.95
5.4.280.0030.19411.03
5.4.270.0030.18811.28
5.4.260.0130.19910.94
5.4.250.0130.31411.21
5.4.240.0060.20411.30
5.4.230.0160.21711.18
5.4.220.0070.25311.34
5.4.210.0180.20411.12
5.4.200.0130.19210.97
5.4.190.0030.19811.02
5.4.180.0030.28810.84
5.4.170.0130.25111.21
5.4.160.0000.20211.07
5.4.150.0070.25911.19
5.4.140.0130.19411.20
5.4.130.0130.21011.46
5.4.120.0100.21211.17
5.4.110.0070.24611.14
5.4.100.0160.19611.48
5.4.90.0100.19111.10
5.4.80.0060.19911.13
5.4.70.0130.19511.08
5.4.60.0060.24611.29
5.4.50.0160.20311.11
5.4.40.0100.21611.17
5.4.30.0030.19911.23
5.4.20.0100.28111.38
5.4.10.0090.19511.33
5.4.00.0000.25710.87
5.3.290.0100.31110.66
5.3.280.0100.22110.52
5.3.270.0000.25610.65
5.3.260.0130.22010.46
5.3.250.0130.25410.64
5.3.240.0100.22910.27
5.3.230.0100.20510.60
5.3.220.0030.23610.55
5.3.210.0130.23110.45
5.3.200.0130.20710.28
5.3.190.0100.21910.27
5.3.180.0130.21510.64
5.3.170.0090.20910.70
5.3.160.0030.36910.73
5.3.150.0070.24610.74
5.3.140.0030.36210.59
5.3.130.0130.22710.52
5.3.120.0100.27710.34
5.3.110.0070.21810.51
5.3.100.0130.26810.55
5.3.90.0130.22210.72
5.3.80.0130.19510.38
5.3.70.0030.20710.33
5.3.60.0070.22010.38
5.3.50.0100.21510.70
5.3.40.0060.21210.71
5.3.30.0000.22810.68
5.3.20.0100.21110.51
5.3.10.0120.28710.35
5.3.00.0170.19110.46
5.2.170.0100.2969.95
5.2.160.0090.2919.95
5.2.150.0090.2919.95
5.2.140.0000.3449.95
5.2.130.0190.2769.95
5.2.120.0090.2869.95
5.2.110.0030.2809.95
5.2.100.0030.3119.95
5.2.90.0130.3699.95
5.2.80.0150.3469.95
5.2.70.0070.2919.95
5.2.60.0030.2889.95
5.2.50.0100.2849.95
5.2.40.0070.3199.95
5.2.30.0100.3079.95
5.2.20.0030.3089.95
5.2.10.0130.2899.95
5.2.00.0060.3689.95
5.1.60.0000.3239.95
5.1.50.0100.3129.95
5.1.40.0070.3039.95
5.1.30.0030.2989.95
5.1.20.0070.4159.95
5.1.10.0030.3859.95
5.1.00.0030.4059.95
5.0.50.0160.6069.95
5.0.40.0130.5049.95
5.0.30.0100.4679.95
5.0.20.0030.4939.95
5.0.10.0130.4639.95
5.0.00.0030.5339.95
4.4.90.0100.6409.95
4.4.80.0090.7599.95
4.4.70.0030.7509.95
4.4.60.0030.7809.95
4.4.50.0100.6459.95
4.4.40.0100.6129.95
4.4.30.0100.6169.95
4.4.20.0070.8059.95
4.4.10.0100.6159.95
4.4.00.0030.7359.95
4.3.110.0030.6979.95
4.3.100.0070.7079.95
4.3.90.0030.8219.95
4.3.80.0030.8839.95
4.3.70.0031.0139.95
4.3.60.0100.8309.95
4.3.50.0000.8479.95
4.3.40.0030.9619.95
4.3.30.0030.8889.95
4.3.20.0891.1049.95
4.3.10.0921.2399.95
4.3.00.0901.1069.95

preferences:
49.71 ms | 403 KiB | 5 Q