Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Microtime plugin for: This page was generated in ...

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
JurgenD
Smarty Rookie


Joined: 20 Jul 2005
Posts: 12
Location: Belgium

PostPosted: Wed Jul 20, 2005 5:09 pm    Post subject: Microtime plugin for: This page was generated in ... Reply with quote

// 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

Smile
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jul 20, 2005 5:12 pm    Post subject: Reply with quote

You may be interested in this:

http://www.phpinsider.com/smarty-forum/viewtopic.php?p=5750#5750
Back to top
View user's profile Send private message
JurgenD
Smarty Rookie


Joined: 20 Jul 2005
Posts: 12
Location: Belgium

PostPosted: Wed Jul 20, 2005 5:25 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jul 20, 2005 5:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
JurgenD
Smarty Rookie


Joined: 20 Jul 2005
Posts: 12
Location: Belgium

PostPosted: Wed Jul 20, 2005 5:57 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP