3v4l.org

run code in 300+ PHP versions simultaneously
<?php // needed to cope with a million entry array //ini_set('memory_limit', '512M'); $limit = 500000; $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()'; ####################################################### foreach($results AS $test) { echo $test['name']." -- ".sprintf("%01.6f", $test['time'])."\n"; } ####################################################### 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.2.00.0400.13779.46
7.1.70.0100.10877.13
7.1.60.0270.17677.41
7.1.50.0600.17077.07
7.1.00.0100.23382.27
7.0.200.7640.14376.36
7.0.140.0130.28082.19
7.0.60.0270.17380.55
7.0.50.0330.21078.52
7.0.40.0270.22335.80
7.0.30.0530.19035.84
7.0.20.0700.22335.73
7.0.10.0200.19735.76
7.0.00.0100.24735.73
5.6.280.0230.14085.78
5.6.210.0270.14785.13
5.6.200.0270.11082.73
5.6.190.0270.11785.05
5.6.180.3230.10385.03
5.6.170.0400.12085.09
5.6.160.0200.10384.97
5.6.150.0370.13082.78
5.6.140.0270.12782.77
5.6.130.0230.08382.82
5.6.120.0400.10085.63
5.6.110.0330.10385.55
5.6.100.0170.15385.64
5.6.90.0170.16385.61
5.6.80.0230.12785.05
5.6.70.4570.09085.13
5.5.350.0500.13785.00
5.5.340.0300.13782.62
5.5.330.0430.14384.85
5.5.320.4170.09384.84
5.5.310.0300.09384.79
5.5.300.0270.08782.60
5.5.290.0200.10082.58
5.5.280.0230.11785.46
5.5.270.0300.08785.42
5.5.260.0170.09385.31
5.5.250.0230.08385.32
5.5.240.0400.11784.82
5.4.450.0730.11384.05
5.4.440.0670.11383.88
5.4.430.0830.11784.13
5.4.420.0500.10783.75
5.4.410.0770.09783.87
5.4.400.0300.11783.73
5.4.390.0670.09383.59
5.4.380.1370.13083.22
5.4.370.1300.13083.25
5.4.360.1500.14383.36
5.4.350.1530.12383.27
5.4.340.1270.13083.19
5.4.320.0220.10177.23
5.4.310.0250.09177.23
5.4.300.0220.08677.23
5.4.290.0230.08777.22
5.4.280.0230.08577.13
5.4.270.0200.12077.12
5.4.260.0250.09077.12
5.4.250.0190.09177.12
5.4.240.0230.08677.12
5.4.230.0200.09577.12
5.4.220.0220.09277.11
5.4.210.0180.09477.11
5.4.200.0250.09177.11
5.4.190.0250.09477.11
5.4.180.0310.13277.11
5.4.170.0240.14977.11
5.4.160.0210.09977.11
5.4.150.0250.08477.11
5.4.140.0210.08776.79
5.4.130.0200.08776.79
5.4.120.0220.08576.74
5.4.110.0190.09376.73
5.4.100.0200.08976.74
5.4.90.0160.09476.74
5.4.80.0190.08876.73
5.4.70.0250.07976.73
5.4.60.0240.08276.73
5.4.50.0180.08876.73
5.4.40.0300.08776.72
5.4.30.0290.08576.71
5.4.20.0240.08976.71
5.4.10.0270.08276.71
5.4.00.0200.08676.21
5.3.290.0230.09976.11
5.3.280.0230.09376.04
5.3.270.0210.10376.05
5.3.260.0290.09176.05
5.3.250.0220.09276.06
5.3.240.0170.09676.06
5.3.230.0190.09576.96
5.3.220.0220.09076.02
5.3.210.0220.09676.01
5.3.200.0290.08776.02
5.3.190.0300.08676.02
5.3.180.0170.09776.01
5.3.170.0250.08976.01
5.3.160.0280.09576.02
5.3.150.0220.09476.01
5.3.140.0300.08476.00
5.3.130.0160.10076.00
5.3.120.0190.09976.00
5.3.110.0190.09876.00
5.3.100.0180.09575.48
5.3.90.0300.08475.47
5.3.80.0230.08975.46
5.3.70.0210.08975.46
5.3.60.0270.09275.44
5.3.50.0210.11875.39
5.3.40.0190.09875.39
5.3.30.0240.08875.35
5.3.20.0230.11175.13
5.3.10.0260.08875.09
5.3.00.0240.09475.08
5.2.170.0210.11473.09
5.2.160.0270.10273.09
5.2.150.0240.12973.09
5.2.140.0190.10573.09
5.2.130.0210.09973.05
5.2.120.0340.09073.05
5.2.110.0280.09473.05
5.2.100.0210.10073.05
5.2.90.0220.09673.05
5.2.80.0170.10573.04
5.2.70.0200.10273.04
5.2.60.0220.09772.99
5.2.50.0160.13372.98
5.2.40.0300.11772.96
5.2.30.0240.12572.69
5.2.20.0170.13072.69
5.2.10.0220.09372.59
5.2.00.0501.955197.45
5.1.60.0611.951225.82
5.1.50.0811.932225.82
5.1.40.0821.931225.77
5.1.30.0711.943226.18
5.1.20.0661.941226.18
5.1.10.0681.941225.87
5.1.00.0821.931225.87
5.0.50.0501.961148.05
5.0.40.0411.968147.91
5.0.30.0441.963147.72
5.0.20.0691.945147.69
5.0.10.0481.965147.66
5.0.00.0581.953147.73
4.4.90.0481.960146.11
4.4.80.0591.951146.09
4.4.70.0411.965146.08
4.4.60.0341.972146.08
4.4.50.0501.954146.10
4.4.40.0471.958146.09
4.4.30.0411.964146.09
4.4.20.0541.951146.15
4.4.10.0451.958146.16
4.4.00.0501.958146.12
4.3.110.0481.960146.03
4.3.100.0471.962146.02
4.3.90.0411.968146.03
4.3.80.0521.956146.09
4.3.70.0491.959146.02
4.3.60.0601.957146.02
4.3.50.0531.958146.02
4.3.40.0521.960145.98
4.3.30.0681.943144.79
4.3.20.0501.975144.77
4.3.10.0531.957144.72
4.3.00.0731.213145.74

preferences:
36.72 ms | 400 KiB | 5 Q