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

setting "Page loaded in x.xxx seconds" with smarty

 
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 -> General
View previous topic :: View next topic  
Author Message
ZeroFill
Smarty Rookie


Joined: 31 Aug 2003
Posts: 28

PostPosted: Sun Aug 31, 2003 11:19 pm    Post subject: setting "Page loaded in x.xxx seconds" with smarty Reply with quote

hi, i'm sorry if this has already been discussed. my search didn't come up with anything specific to my question.

before i switched to smarty, i made the normal microtimes in both the header and footer.inc.php files then displayed the difference. is there a way to do this with smarty?

i know can do microtime at the beginning and end of every script but is there a better way of doing this, which also includes smarty compile time?

[edit]
strange. i can't change the topic. i forgot the question mark

[edit2]
n/m. i guess i can always make my own template function
Back to top
View user's profile Send private message
boots
Administrator


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

PostPosted: Mon Sep 01, 2003 12:02 am    Post subject: Reply with quote

Hi Zerofill.

Reporting time from Smarty directly will ignore other things that take time--for example, the creation of your business objects, the smarty classes, application logic, db access...the list goes on.

If you do want to time blocks within Smarty, your idea of a template function is valid, though I suggest a block function. I wrote something like that which you may find of use: block function: timeblock.
Back to top
View user's profile Send private message
ZeroFill
Smarty Rookie


Joined: 31 Aug 2003
Posts: 28

PostPosted: Mon Sep 01, 2003 12:03 am    Post subject: Reply with quote

i made a quick hacked Template Function for anyone that might want or improve upon it

[php:1:3516362ac1]
<?php
/*
* Smarty plugin
* ----------------------------------------
* File: function.page_load.php
* Type: function
* Name: page_load
* Purpose: outputs the difference between ending microtime and beginning microtime
* Note: MUST $smarty->assign('start_load_time', $start_load_time) for it to work.
* ------------------------------------------
*/

function smarty_function_page_load($params, &$smarty)
{
$start_load_time = $smarty->get_template_vars('start_load_time');
if (empty($start_load_time))
{
$smarty->trigger_error("assign: missing 'start_load_time'");
return;
}
return $smarty->_get_microtime() - $start_load_time;
}
?> [/php:1:3516362ac1]

example
Code:

// index.php
$mtime = microtime();
$mtime = explode(" ", $mtime);
$start_load_time = (double)($mtime[1]) + (double)($mtime[0]);

..some code..
$smarty->assign('start_load_time',$start_load_time);
$smarty->display('index.tpl');

// footer.tpl
Page loaded in <{page_load|truncate:8:""}> seconds


[edit]
thanks for the link. i'm sure it'll be more accurate than mine Smile

[edit]
yep. the results are surprisingly different
mine: Page loaded in 0.102422 seconds (and jumps between .09 and .5 for some reason)
yours: [page_load] Elapsed Time 0.048163s Shocked
Back to top
View user's profile Send private message
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 -> General 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