note 21523 added to function.echo

From: Date: Thu, 16 May 2002 00:29:20 +0000
Subject: note 21523 added to function.echo
Groups: php.notes 
Request: Send a blank email to php-notes+get-30694@lists.php.net to get a copy of this message
When possible, it is faster to pass multiple parameters to echo versus passing one parameter which is many concatinations. Below is a script which will preform a quick benchmark for you to see: <?php function getmicrotime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } $args=array(); for($i=0;$i<10000;$i++) $args[]="'line to output number $i\n'"; $concatEcho="echo ".implode("\n.",$args).";"; $paramEcho="echo ".implode("\n,",$args).";"; unset($args); $startParam=getmicrotime(); eval($paramEcho); $endParam=getmicrotime(); $startConcat=getmicrotime(); eval($concatEcho); $endConcat=getmicrotime(); $concatTime=$endConcat-$startConcat; $paramTime=$endParam-$startParam; print "\nConcats took $concatTime seconds\nParams took $paramTime\n"; ?> The results I got when running the script above were 6.047 seconds for concatinations and 1.781 seconds for parameter passing. This was just executing the script via command line, having the output dumped to a console. The performace increase is even greater when using a script on a webpage with output buffering. -- http://www.php.net/manual/en/function.echo.php http://master.php.net/manage/user-notes.php?action=edit+21523 http://master.php.net/manage/user-notes.php?action=delete+21523 http://master.php.net/manage/user-notes.php?action=reject+21523

« previous php.notes (#30694) next »