note 21523 deleted from function.echo by betz
| From: | betz@php.net | Date: | Wed, 11 Jan 2006 14:24:57 +0000 |
| Subject: | note 21523 deleted from function.echo by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-101556@lists.php.net to get a copy of this message | ||
Note Submitter: asmo at mail dot utexas dot edu
----
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.