View previous topic :: View next topic |
Author |
Message |
Frank Smarty Rookie
Joined: 18 Apr 2003 Posts: 6
|
Posted: Mon Apr 21, 2003 7:01 pm Post subject: Parsetime calculation |
|
|
I don't know if it is usefull but why not:
I was wondering if there could be a function build into smarty that could calculate parsetime such as:
{parsetime start}
blalalalaa html etc more html
Page parsed in {/parsetime end}
And template parsetime as well but that is a bit lazy I think :[img][/img] |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Apr 21, 2003 7:43 pm Post subject: |
|
|
The debug console has a lot of parse time functionality built in. Or are you referring to something that would display at the bottom of the web page? |
|
Back to top |
|
Frank Smarty Rookie
Joined: 18 Apr 2003 Posts: 6
|
Posted: Mon Apr 21, 2003 10:28 pm Post subject: |
|
|
Yeah something like: Total parsetime: $bla Template parsing done in: $bla1. Would be nice to have it |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Tue Apr 22, 2003 4:48 am Post subject: |
|
|
I'm wondering what the best way would be to go about it. It's no problem collecting the parsetime for a call to display(), but the problem is you don't know the parsetime until <i>after</i> the template is parsed, so it's too late to put the parsetime in the template I suppose a post-filter could plug the parsetime in afterwards... but you wouldn't want to have to test for that when it's not used.
Monte |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Tue Apr 22, 2003 5:27 am Post subject: |
|
|
At first, I was thinking along the lines of mohrt as well--how to report the time before the deed is done? Then I wondered if Frank was really meaning "time the following block of code". That would imply timing a portion of the template and not the entire display() call.
perhaps like:
Code: | {timeblock name=myblock}
blalalalaa html etc more html
{/timeblock}
Block parsed in {$myblock.parsetime} |
As to mohrt's question, one way of providing timing values back is to create 'special' smarty constants. When the special constants are not detected in a template use standard one-pass processing with no timing code. When special constants are detected in a template, revert to a two-pass process--the first exactly the same as the prior case, except that timing code is enabled and the special constants ignored. The second pass replaces the constants with the collected timing results from the first pass. Shouldn't be a big deal performance wise as it should only be used during debugging (yes? no?) and only collects timing for the first pass, which is the normal operating case.
Hmmm. My gut says that it is something better left in the API as opposed to being available from templates directly. That may just be because I can't see what use it is to anyone but developers (including template developers) when that info is mostly already provided by the debug console. |
|
Back to top |
|
mocean Smarty Rookie
Joined: 21 May 2003 Posts: 30 Location: The Netherlands
|
Posted: Fri May 23, 2003 11:27 am Post subject: |
|
|
I'm also interested in this feature. Isn't it possible to do this with one or two custom functions?
Like
Code: |
{timer name="timer1" option="start"}
code here
{timer name="timer1" option="end"}
more code
{timer name="timer1" option="display"}
|
In this way they can also be nested easily:
Like
Code: |
{timer name="timer1" option="start"}
code here
{timer name="timer2" option="start"}
code here
{timer name="timer2" option="end"}
{timer name="timer1" option="end"}
more code
{timer name="timer1" option="display"}
{timer name="timer2" option="display"}
|
You could also put the values in variables $timer1 and $timer2 after the end is called.
Although, I'm wondering if you really measure a realistic time this way. I am to new to Smarty to oversee that |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri May 23, 2003 2:48 pm Post subject: |
|
|
@mocean: if you are running a CVS version of Smarty, you may be interested in this plugin. |
|
Back to top |
|
|