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.0080.03612.52
5.4.300.0070.03512.52
5.4.290.0050.03812.52
5.4.280.0050.03612.41
5.4.270.0050.03612.41
5.4.260.0060.03612.41
5.4.250.0050.03812.41
5.4.240.0070.03412.41
5.4.230.0050.03812.40
5.4.220.0070.03512.41
5.4.210.0070.03512.40
5.4.200.0070.03712.41
5.4.190.0050.03612.40
5.4.180.0080.03412.40
5.4.170.0070.03412.41
5.4.160.0050.03612.40
5.4.150.0040.03712.40
5.4.140.0050.03812.09
5.4.130.0050.03512.07
5.4.120.0070.03412.04
5.4.110.0050.03612.03
5.4.100.0080.03312.03
5.4.90.0080.03512.04
5.4.80.0070.03512.04
5.4.70.0040.03612.03
5.4.60.0050.03512.03
5.4.50.0060.03512.03
5.4.40.0070.03312.02
5.4.30.0040.03712.01
5.4.20.0070.03412.01
5.4.10.0080.03312.01
5.4.00.0040.03811.51
5.3.280.0090.03512.71
5.3.270.0060.03912.72
5.3.260.0060.04112.72
5.3.250.0050.03812.72
5.3.240.0040.03812.72
5.3.230.0070.03612.71
5.3.220.0070.03612.68
5.3.210.0050.03812.68
5.3.200.0070.03512.68
5.3.190.0060.03712.68
5.3.180.0070.03512.67
5.3.170.0040.03812.67
5.3.160.0070.03512.67
5.3.150.0050.03612.68
5.3.140.0090.03212.66
5.3.130.0090.03512.66
5.3.120.0090.03512.66
5.3.110.0070.03612.66
5.3.100.0080.03412.12
5.3.90.0070.03612.09
5.3.80.0050.03612.08
5.3.70.0090.03412.08
5.3.60.0050.03712.07
5.3.50.0070.03912.02
5.3.40.0050.04112.02
5.3.30.0100.03811.98
5.3.20.0080.03911.76
5.3.10.0060.03611.72
5.3.00.0090.03411.71
5.2.170.0050.0299.22
5.2.160.0050.0299.21
5.2.150.0060.0289.22
5.2.140.0070.0289.21
5.2.130.0040.0309.17
5.2.120.0040.0309.17
5.2.110.0050.0299.18
5.2.100.0070.0279.18
5.2.90.0070.0289.18
5.2.80.0070.0279.17
5.2.70.0050.0299.17
5.2.60.0040.0299.13
5.2.50.0040.0309.09
5.2.40.0050.0279.07
5.2.30.0050.0309.04
5.2.20.0040.0309.04
5.2.10.0060.0278.96
5.2.00.0050.0318.81
5.1.60.0040.0258.11
5.1.50.0040.0258.10
5.1.40.0040.0258.08
5.1.30.0040.0258.43
5.1.20.0040.0258.46
5.1.10.0040.0258.18
5.1.00.0090.0218.17
5.0.50.0050.0186.68
5.0.40.0030.0196.54
5.0.30.0040.0306.35
5.0.20.0030.0196.32
5.0.10.0050.0196.29
5.0.00.0040.0296.29
4.4.90.0040.0154.78
4.4.80.0010.0174.75
4.4.70.0020.0154.75
4.4.60.0050.0134.75
4.4.50.0020.0174.77
4.4.40.0050.0234.71
4.4.30.0040.0144.76
4.4.20.0040.0154.85
4.4.10.0040.0154.85
4.4.00.0020.0254.76
4.3.110.0040.0154.67
4.3.100.0020.0164.67
4.3.90.0020.0144.63
4.3.80.0040.0234.58
4.3.70.0030.0154.63
4.3.60.0030.0204.62
4.3.50.0020.0164.63
4.3.40.0020.0254.54
4.3.30.0020.0163.34
4.3.20.0030.0173.32
4.3.10.0020.0193.29
4.3.00.0000.0237.20

preferences:
141.04 ms | 1394 KiB | 7 Q