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()'; ####################################################### 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)
5.4.310.0070.03612.52
5.4.300.0070.03812.52
5.4.290.0070.03712.52
5.4.280.0080.03612.41
5.4.270.0070.04012.41
5.4.260.0040.03812.41
5.4.250.0060.03712.41
5.4.240.0080.03412.41
5.4.230.0050.04112.40
5.4.220.0060.03512.40
5.4.210.0060.03812.41
5.4.200.0070.03712.40
5.4.190.0050.03612.40
5.4.180.0090.03612.40
5.4.170.0090.03612.41
5.4.160.0060.03512.40
5.4.150.0040.03812.40
5.4.140.0050.04112.09
5.4.130.0060.03512.07
5.4.120.0050.04012.04
5.4.110.0040.03712.03
5.4.100.0050.03512.04
5.4.90.0070.03612.03
5.4.80.0050.03612.04
5.4.70.0040.03612.03
5.4.60.0070.03412.03
5.4.50.0070.03412.03
5.4.40.0070.03412.02
5.4.30.0060.03912.02
5.4.20.0060.03512.01
5.4.10.0070.03312.01
5.4.00.0040.03811.51
5.3.280.0090.03412.71
5.3.270.0050.03912.72
5.3.260.0050.03812.72
5.3.250.0060.03812.72
5.3.240.0050.04112.72
5.3.230.0070.03612.71
5.3.220.0050.03812.68
5.3.210.0100.03412.68
5.3.200.0070.03412.68
5.3.190.0040.03912.68
5.3.180.0090.03412.67
5.3.170.0090.03512.67
5.3.160.0100.03412.67
5.3.150.0080.03912.67
5.3.140.0040.03812.66
5.3.130.0100.03812.66
5.3.120.0070.03712.66
5.3.110.0080.03812.66
5.3.100.0050.03812.12
5.3.90.0040.03812.09
5.3.80.0070.03812.08
5.3.70.0040.03812.08
5.3.60.0050.03612.07
5.3.50.0070.03512.02
5.3.40.0080.03612.02
5.3.30.0060.03311.98
5.3.20.0040.03611.76
5.3.10.0050.03711.72
5.3.00.0030.04111.71
5.2.170.0050.0309.21
5.2.160.0050.0339.22
5.2.150.0040.0309.22
5.2.140.0040.0319.21
5.2.130.0050.0299.17
5.2.120.0050.0309.17
5.2.110.0030.0309.18
5.2.100.0040.0299.18
5.2.90.0050.0279.18
5.2.80.0060.0339.17
5.2.70.0040.0309.17
5.2.60.0030.0319.12
5.2.50.0090.0319.09
5.2.40.0050.0329.07
5.2.30.0040.0309.04
5.2.20.0050.0299.04
5.2.10.0040.0288.96
5.2.00.0040.0308.82
5.1.60.0050.0238.10
5.1.50.0050.0258.10
5.1.40.0050.0238.08
5.1.30.0040.0258.43
5.1.20.0040.0268.46
5.1.10.0040.0258.17
5.1.00.0040.0258.17
5.0.50.0020.0216.69
5.0.40.0040.0186.54
5.0.30.0040.0306.35
5.0.20.0020.0216.32
5.0.10.0040.0236.29
5.0.00.0050.0306.29
4.4.90.0020.0164.78
4.4.80.0010.0184.75
4.4.70.0020.0154.76
4.4.60.0040.0164.76
4.4.50.0020.0154.77
4.4.40.0020.0254.71
4.4.30.0020.0164.76
4.4.20.0020.0154.85
4.4.10.0040.0144.85
4.4.00.0040.0234.76
4.3.110.0030.0174.67
4.3.100.0040.0144.66
4.3.90.0020.0164.63
4.3.80.0040.0234.58
4.3.70.0020.0154.63
4.3.60.0060.0104.63
4.3.50.0030.0184.62
4.3.40.0030.0254.54
4.3.30.0010.0163.34
4.3.20.0020.0153.32
4.3.10.0120.63237.70
4.3.00.0300.94038.96

preferences:
135.3 ms | 1394 KiB | 7 Q