|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
JurgenD Smarty Rookie
Joined: 20 Jul 2005 Posts: 12 Location: Belgium
|
Posted: Wed Jul 20, 2005 5:09 pm Post subject: Microtime plugin for: This page was generated in ... |
|
|
// smarty function: stopwatch
// Descr : This function calculates parse time of Your templates
// in microtime
// Author: DEBO Jurgen E. G.
// Usage : Call this twice on top of Your template, and before </body>
// Ex:
// {stopwatch}
// <html>
// ...
// <p>This page was generated in {stopwatch} seconds</p>
// </body>
// Call : $smarty->register_function('stopwatch', 'stopwatch', false);
// note : Function may NOT be cached
//
function stopwatch($params, &$smarty){
static $mt_previous = 0;
list($usec, $sec) = explode(" ",microtime());
$mt_current = (float)$usec + (float)$sec;
if (!$mt_previous) {
$mt_previous = $mt_current;
return "";
} else {
$mt_diff = ($mt_current - $mt_previous);
$mt_previous = $mt_current;
return sprintf('%.16f',$mt_diff);
}
}
Additionally:
* Request for feature: $smarty.getmicrotime
|
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
|
Back to top |
|
JurgenD Smarty Rookie
Joined: 20 Jul 2005 Posts: 12 Location: Belgium
|
Posted: Wed Jul 20, 2005 5:25 pm Post subject: |
|
|
Yes, thanks for the source !
I have a similar approuch with another piece of code, to create a stopwatch function for timing some sections. And this URL shows this approuch.
However.
My approuch was to generate as FAST as possible a diff parse
time to have a quick reply for parsing time. If You calculate the pasing time of a generated page, Your function does need to be short and fast,
to have sharp results.
Additionally, this function works with a STATIC variable to remember start of parsing.
So BOTH are needed.
I post it in the other thread. Thanks. |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Jul 20, 2005 5:34 pm Post subject: |
|
|
Yes, please post your solution -- it sounds nice.
FWIW, I Personally hink it is useful to do timing for relative metrics. I have no expectations or real need for high-precision. I see generation time as a developer/operations issue -- I doubt users care since their round-trip time has several other mitigating (and typically more important) factors involved.
Greetings. |
|
Back to top |
|
JurgenD Smarty Rookie
Joined: 20 Jul 2005 Posts: 12 Location: Belgium
|
Posted: Wed Jul 20, 2005 5:57 pm Post subject: |
|
|
boots wrote: | Yes, please post your solution -- it sounds nice.
I doubt users care since their round-trip time has several other mitigating (and typically more important) factors involved.
Greetings. |
Yes. Indeed. Thats why I use only as comment in my pages:
Code: |
<!-- This page is generated in {stopwatch} -->
|
To fine tune the function:
Replace:
Code: |
list($usec, $sec) = explode(" ",microtime());
$mt_current = (float)$usec + (float)$sec;
|
With:
Code: |
$mt_current = (float) array_sum(explode(' ', microtime()));
|
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|