3v4l.org

run code in 300+ PHP versions simultaneously
<?php // needed to cope with a million entry array ini_set('memory_limit', '512M'); $limit = 100000; $text[] = "Now is the time"; $text[] = "for all good men"; $text[] = "to come to the aid"; $text[] = "of their country."; $text2['part1'] = "Now is the time"; $text2['part2'] = "for all good men"; $text2['part3'] = "to come to the aid"; $text2['part4'] = "of their country."; $bigArray = fillArray($limit); $max=count($bigArray); ####################################################### $start = microtime(TRUE); for($i=0; $i<$max; $i++) { $bigArray[$i] = $text[0]; $bigArray[$i] .= ' '; $bigArray[$i] .= $text[1]; $bigArray[$i] .= ' '; $bigArray[$i] .= $text[2]; $bigArray[$i] .= ' '; $bigArray[$i] .= $text[3]; } $results['dotequal']['time'] = microtime(TRUE) - $start; $results['dotequal']['name'] = 'Dot Equals'; ####################################################### $start = microtime(TRUE); for($i=0; $i<$max; $i++) { $bigArray[$i] = $text[0].' '.$text[1].' '.$text[2].' '.$text[3]; } $results['concat']['time'] = microtime(TRUE) - $start; $results['concat']['name'] = 'Dot Concatenation'; ####################################################### $start = microtime(TRUE); for($i=0; $i<$max; $i++) { $bigArray[$i] = "$text[0] $text[1] $text[2] $text[3]"; } $results['replace']['time'] = microtime(TRUE) - $start; $results['replace']['name'] = 'In-string Replacement'; ####################################################### $start = microtime(TRUE); for($i=0; $i<$max; $i++) { $bigArray[$i] = "{$text2['part1']} {$text2['part2']} {$text2['part3']} {$text2['part4']}"; } $results['replace2']['time'] = microtime(TRUE) - $start; $results['replace2']['name'] = 'Complex In-string Replacement'; ####################################################### $start = microtime(TRUE); for($i=0; $i<$max; $i++) { $bigArray[$i] = sprintf('%s %s %s %s', $text[0], $text[1], $text[2], $text[3]); } $results['sprintf']['time'] = microtime(TRUE) - $start; $results['sprintf']['name'] = 'Function: sprintf()'; ####################################################### $start = microtime(TRUE); for($i=0; $i<$max; $i++) { $bigArray[$i] = implode(' ', $text); } $results['implode']['time'] = microtime(TRUE) - $start; $results['implode']['name'] = 'Function: implode()'; ####################################################### echo "<table width=\"400\" cellspacing=\"3\">\n"; echo "<tr><td width=\"50%\"><strong>Array Size:</strong></td><td width=\"50%\"><strong>$limit</strong></td></tr>\n"; foreach($results AS $test) { echo "<tr><td>".$test['name']."</td><td>".sprintf("%01.6f", $test['time'])."</td></tr>\n"; } echo "</table>"; ####################################################### function fillArray($limit) { // build huge array for($i=0; $i<$limit; $i++) { $array[] = $i; } return $array; } ?>

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.0200.18870.04
7.4.00.0460.21570.03
7.3.130.0460.20970.02
7.3.120.0430.21070.05
7.3.110.0200.15669.93
7.3.100.0400.14770.07
7.3.90.0300.19870.25
7.3.80.0270.15070.00
7.3.70.0230.18670.05
7.3.60.0500.20270.15
7.3.50.0200.15870.18
7.3.40.0330.17369.96
7.3.30.0240.18569.83
7.3.20.0230.15872.10
7.3.10.0300.14371.04
7.3.00.0470.16371.19
7.2.260.0300.18170.07
7.2.250.0200.17970.50
7.2.240.0370.14670.21
7.2.230.0300.19970.53
7.2.220.0300.17870.41
7.2.210.0100.16670.55
7.2.200.0300.22770.47
7.2.190.0230.20270.18
7.2.180.0370.16170.11
7.2.170.0330.15270.34
7.2.160.0430.21470.23
7.2.150.0230.18272.29
7.2.140.0200.18072.50
7.2.130.0600.18571.43
7.2.120.0760.16171.49
7.2.110.0950.16071.40
7.2.100.0820.13871.62
7.2.90.0970.16571.42
7.2.80.1150.14571.48
7.2.70.0990.17671.62
7.2.60.1200.14671.35
7.2.50.0800.15471.38
7.2.40.0690.16971.39
7.2.30.0970.16871.58
7.2.20.0730.15971.41
7.2.10.0770.16771.59
7.2.00.0760.13772.25
7.1.330.0270.22371.22
7.1.320.0170.22671.38
7.1.310.2320.23371.64
7.1.300.0200.22171.45
7.1.290.0130.19071.35
7.1.280.0330.19671.27
7.1.270.0270.18071.29
7.1.260.0170.21371.21
7.1.250.0860.21670.40
7.1.240.0170.17771.23
7.1.230.0140.19371.18
7.1.220.0070.19771.30
7.1.210.0150.19271.28
7.1.200.0320.18471.24
7.1.190.0230.18971.39
7.1.180.0310.21171.48
7.1.170.0220.21071.24
7.1.160.0170.21571.27
7.1.150.0230.18371.46
7.1.140.0200.20671.33
7.1.130.0140.21771.25
7.1.120.0270.20071.38
7.1.110.0180.20671.43
7.1.100.0320.18171.22
7.1.90.0290.17871.25
7.1.80.0130.20071.44
7.1.70.0170.16771.34
7.1.60.0190.16871.21
7.1.50.0560.17571.12
7.1.40.0100.22671.42
7.1.30.0460.19171.43
7.1.20.0290.18671.47
7.1.10.0240.19271.29
7.1.00.0190.10443.73
7.0.330.2080.18571.05
7.0.320.0230.19671.03
7.0.310.0100.21471.04
7.0.300.0130.20271.10
7.0.290.0160.23570.95
7.0.280.0070.20471.06
7.0.270.0140.21470.94
7.0.260.0160.20671.05
7.0.250.0100.20571.08
7.0.240.0470.18271.10
7.0.230.0140.21971.03
7.0.220.0290.19171.12
7.0.210.0070.20871.01
7.0.200.0360.16270.88
7.0.190.0200.19271.01
7.0.180.0230.18771.06
7.0.170.0240.23671.19
7.0.160.0160.19671.13
7.0.150.0320.18571.05
7.0.140.0230.20073.61
7.0.130.0200.20871.19
7.0.120.0230.00012.84
7.0.110.0170.21671.13
7.0.100.0230.12229.07
7.0.90.0200.23171.09
7.0.80.0320.19371.19
7.0.70.0330.18571.00
7.0.60.0200.18072.38
7.0.50.0260.20171.24
7.0.40.0330.17122.31
7.0.30.0300.18922.35
7.0.20.0370.18222.39
7.0.10.0160.20822.31
7.0.00.0120.21322.43
5.6.400.0260.45855.34
5.6.390.0370.42955.76
5.6.380.0170.38855.41
5.6.370.0300.38255.73
5.6.360.0300.40555.63
5.6.350.0420.37255.52
5.6.340.0470.35655.67
5.6.330.0270.39955.92
5.6.320.0300.39655.91
5.6.310.0390.41455.30
5.6.300.0300.37755.87
5.6.290.0360.36555.62
5.6.280.0250.43458.15
5.6.270.0320.39355.79
5.6.260.0330.39755.32
5.6.250.0390.35755.80
5.6.240.0380.36455.30
5.6.230.0370.37255.37
5.6.220.0260.43355.77
5.6.210.0210.31857.94
5.6.200.0250.24048.34
5.6.190.0340.36557.82
5.6.180.2220.34057.84
5.6.170.0350.33157.85
5.6.160.0250.31357.69
5.6.150.0280.31156.81
5.6.140.0250.29356.53
5.6.130.0350.34356.82
5.6.120.0220.33758.13
5.6.110.0350.38158.04
5.6.100.0150.31958.20
5.6.90.0250.34758.17
5.6.80.0180.33157.74
5.6.70.1990.30257.64
5.6.60.0370.35055.55
5.6.50.0200.37655.55
5.6.40.0170.38455.53
5.6.30.0300.42455.47
5.6.20.0370.35955.32
5.6.10.0300.39655.49
5.6.00.0440.39655.56
5.5.380.0200.42555.39
5.5.370.0440.37655.75
5.5.360.0260.37455.61
5.5.350.2430.31257.76
5.5.340.0170.33556.50
5.5.330.0250.31257.54
5.5.320.2260.31257.57
5.5.310.0300.33057.72
5.5.300.0230.36056.47
5.5.290.0250.34656.64
5.5.280.0290.30457.93
5.5.270.0300.35557.86
5.5.260.0260.32457.92
5.5.250.0310.35058.00
5.5.240.0410.30957.63
5.5.230.0250.36855.62
5.5.220.0300.41355.24
5.5.210.0360.38655.65
5.5.200.0170.38855.61
5.5.190.0310.37255.52
5.5.180.0290.37855.53
5.5.170.0330.37755.63
5.5.160.0330.40055.66
5.5.150.0370.42855.55
5.5.140.0400.37655.67
5.5.130.0260.37855.54
5.5.120.0260.40755.57
5.5.110.0130.39055.60
5.5.100.0160.45255.39
5.5.90.0170.41855.52
5.5.80.0430.40455.37
5.5.70.0230.36855.58
5.5.60.0220.37655.54
5.5.50.0130.38155.63
5.5.40.0360.36555.48
5.5.30.0330.38855.40
5.5.20.0300.41455.35
5.5.10.0260.43255.37
5.5.00.0500.42455.43
5.4.450.0300.34855.52
5.4.440.0370.37755.69
5.4.430.0520.38355.67
5.4.420.0460.35755.68
5.4.410.0450.38055.63
5.4.400.0450.38855.48
5.4.390.0210.38855.47
5.4.380.0750.43055.22
5.4.370.0650.39955.11
5.4.360.0560.39155.22
5.4.350.0750.38555.11
5.4.340.0650.42055.30
5.4.330.0230.36652.22
5.4.320.0250.34552.19
5.4.310.0240.33752.26
5.4.300.0220.32652.18
5.4.290.0250.34352.13
5.4.280.0280.34352.05
5.4.270.0190.34552.22
5.4.260.0140.33752.19
5.4.250.0230.33752.02
5.4.240.0210.34652.12
5.4.230.0120.33952.01
5.4.220.0210.32752.21
5.4.210.0150.34552.13
5.4.200.0290.31952.17
5.4.190.0190.32752.23
5.4.180.0170.35852.10
5.4.170.0250.35752.13
5.4.160.0170.32752.10
5.4.150.0280.35452.05
5.4.140.0210.33551.94
5.4.130.0190.36451.99
5.4.120.0200.33851.87
5.4.110.0180.35951.92
5.4.100.0190.38952.04
5.4.90.0280.35951.89
5.4.80.0280.36551.86
5.4.70.0250.35551.98
5.4.60.0190.34551.94
5.4.50.0190.38752.01
5.4.40.0200.35751.95
5.4.30.0150.34651.84
5.4.20.0130.34051.95
5.4.10.0240.35851.96
5.4.00.0200.36351.67
5.3.290.0260.38051.67
5.3.280.0150.37151.54
5.3.270.0220.37451.60
5.3.260.0230.37251.57
5.3.250.0280.37651.59
5.3.240.0280.37951.52
5.3.230.0160.38951.58
5.3.220.0200.39251.46
5.3.210.0250.42551.49
5.3.200.0170.41651.51
5.3.190.0240.39851.49
5.3.180.0210.41951.60
5.3.170.0220.42551.55
5.3.160.0280.41851.62
5.3.150.0300.37351.55
5.3.140.0240.41851.59
5.3.130.0320.36051.54
5.3.120.0210.39651.53
5.3.110.0150.41151.60
5.3.100.0230.41651.34
5.3.90.0180.42551.28
5.3.80.0320.39151.17
5.3.70.0200.37151.14
5.3.60.0280.40351.16
5.3.50.0220.39651.16
5.3.40.0300.38251.15
5.3.30.0130.37351.19
5.3.20.0220.37751.06
5.3.10.0180.41651.04
5.3.00.0230.40250.89
5.2.170.0120.34847.22
5.2.160.0210.32747.22
5.2.150.0190.33247.22
5.2.140.0160.34447.21
5.2.130.0150.32947.18
5.2.120.0150.35447.18
5.2.110.0180.32647.18
5.2.100.0140.32547.18
5.2.90.0180.36947.17
5.2.80.0210.33947.16
5.2.70.0160.33847.16
5.2.60.0180.33547.12
5.2.50.0200.34347.22
5.2.40.0170.35847.20
5.2.30.0180.34746.91
5.2.20.0130.37146.92
5.2.10.0190.33646.82
5.2.00.0160.34346.94
5.1.60.0170.42851.79
5.1.50.0220.41651.79
5.1.40.0120.43951.77
5.1.30.0230.42452.12
5.1.20.0100.43252.13
5.1.10.0210.42651.86
5.1.00.0190.40651.86
5.0.50.0200.67250.37
5.0.40.0130.69650.22
5.0.30.0130.67650.04
5.0.20.0250.65250.00
5.0.10.0180.69249.98
5.0.00.0150.67149.97
4.4.90.0100.71139.21
4.4.80.0110.68639.20
4.4.70.0150.70339.19
4.4.60.0120.73239.20
4.4.50.0210.69039.21
4.4.40.0220.74039.20
4.4.30.0210.70239.20
4.4.20.0200.69039.26
4.4.10.0180.71739.27
4.4.00.0160.73139.42
4.3.110.0270.68439.05
4.3.100.0170.68639.12
4.3.90.0180.68739.14
4.3.80.0120.73339.27
4.3.70.0130.72539.13
4.3.60.0260.70439.13
4.3.50.0210.69639.13
4.3.40.0350.67439.03
4.3.30.0190.70437.90
4.3.20.0120.65737.88
4.3.10.0130.66337.70
4.3.00.0330.83738.94

preferences:
40.27 ms | 401 KiB | 5 Q