Measuring Compile/Display time.
| From: | Darryl Bleau | Date: | Thu, 09 Jan 2003 21:45:51 +0000 |
| Subject: | Measuring Compile/Display time. | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-7101@lists.php.net to get a copy of this message | ||
In a non-Smarty PHP script, you could do something like this: (code from PHPA page)
<?php
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
?>
<?php
$start = getmicrotime();
... (code) ...
echo sprintf("%.4f",(getmicrotime() - $script_start));
?>
With Smarty, I've done something like this:
(footer.tpl)
<br>
This page took {$compileTime} seconds to display.
</BODY>
</HTML>
and
(index.php)
<?php
...(code)...
$smarty->assign("compileTime",sprintf("%.4f",(getmicrotime() -
$script_start)));
$smarty->display("index.tpl");
?>
and index.tpl includes footer.tpl, of course. But, doing it this way, I'll miss the actual time
it takes for the smarty display() function. Anyway I could do this better? I could put the {php}
tags in the templates I suppose but I was hoping for something more elegant.