Re: jumping between php and html or using echo for printing html-tags.
| From: | Chris Shiflett | Date: | Thu, 06 Feb 2003 22:39:37 +0000 |
| Subject: | Re: jumping between php and html or using echo for printing html-tags. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-134684@lists.php.net to get a copy of this message | ||
--- anders thoresson <listor@thoresson.net> wrote:
> Which is more efficient:
Your first method is more efficient according to my quick
test, though I find myself preferring the second when I
write code due to the readability advantages. The
difference is small, however. Here is the code I used to
test, so you can try it out (and verify my method of
testing) for yourself:
<?
$foo = 'bar';
# TIME FIRST METHOD
list($microseconds, $seconds) = explode(' ', microtime());
$start_time = floatval($seconds) + floatval($microseconds);
for ($i = 0; $i < 100; $i++)
{
echo "a href=\"" . $_SERVER['PHP_SELF'] . "?action=" .
$foo . "\">\n";
}
list($microseconds, $seconds) = explode(' ', microtime());
$end_time = floatval($seconds) + floatval($microseconds);
$total_time_first = $end_time - $start_time;
# TIME SECOND METHOD
list($microseconds, $seconds) = explode(' ', microtime());
$start_time = floatval($seconds) + floatval($microseconds);
for ($i = 0; $i < 100; $i++)
{
?>
<a href="<? echo $_SERVER['PHP_SELF']; ?>?action=<? echo
$foo; ?>">
<?
}
list($microseconds, $seconds) = explode(' ', microtime());
$end_time = floatval($seconds) + floatval($microseconds);
$total_time_second = $end_time - $start_time;
# OUTPUT RESULTS
echo "<p>First method took " . $total_time_first . "
seconds</p>\n";
echo "<p>Second method took " . $total_time_second . "
seconds</p>\n";
?>
Chris