Just out of curiosity I did a small benchmark on a single P2-366 with 64MB, running apache 1.3.14 and php 4.0.4pl1 (yes, ancient I know, but I'm a lazy bugger) without the zend optimizer, accessing the server from an AMD athlon 1.2G running netscape on w2k, through a private 100Mbit halfduplex connection.
At 10 iterations (time in seconds)
0.00070691109 - First
0.0004979372 - Second
100 iterations
0.0092380047 - First
0.013784051 - Second
1000 iterations
0.13782001 - First
0.12125802 - Second
10k iterations
1.5036219 - First
1.3198509 - Second
100k iterations
14.725201 - First
12.729824 - Second
this is the script I used:
$i=100; // number of iterations
$variable='hello'; // set some var to use in printf
$iStart = microtime(); // mark the start time
for ($t=0;$t<$i;$t++)
{
printf("line 1%s", $variable);
?>
html-line 2
html-line 3
html-line 4
<?php
printf("line 5%s", $variable);
?>
html-line 6
html-line 7
html-line 8
html-line 9
<?php
printf("line 10%s", $variable);
};
$iStop = microtime(); //mark the end time
// Calculate the time difference
$aParts = split(' ',$iStart.' '.$iStop);
$sFirstRun = ($aParts[2]+$aParts[3])-($aParts[0]+$aParts[1]);
$iStart = microtime(); // mark the start time
for ($t=0;$t<$i;$t++)
{
printf("line 1%s", $variable);
echo "html-line 2";
echo "html-line 3";
echo "html-line 4";
printf("line 5%s", $variable);
echo "html-line 6";
echo "html-line 7";
echo "html-line 8";
echo "html-line 9";
printf("line 10%s", $variable);
};
$iStop = microtime(); //mark the end time
// Calculate the time difference
$aParts = split(' ',$iStart.' '.$iStop);
$sSecondRun = ($aParts[2]+$aParts[3])-($aParts[0]+$aParts[1]);
// Echo results
echo '<BR>';
echo $sFirstRun.' - First <BR>';
echo $sSecondRun.' - Second<BR>';
exit;