For Programmers: Free Programming Magazines  


Home > Archive > PHP Smarty Templates > July 2004 > Re: [SMARTY] Execution time of {eval ...}









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [SMARTY] Execution time of {eval ...}
Messju Mohr

2004-07-06, 4:11 pm

On Tue, Jul 06, 2004 at 03:45:09PM +0200, Dennis Freise wrote:
> Hi everyone.
>
> I've a question concerning the execution time of an {eval ...} command...
>
> I have a site which uses many templates, and I have the following:
>
> template 1:
> {capture name=post_item}
> {literal}
> a typical post_block with {$vars} and {if expressions} in it
> {/literal}
> {/capture}
>
> template 2:
> {include file="template1"}
> {section name=items loop=$post_items}
> {eval var=$smarty.capture.post_item}
> {/section}
>
> Containing 10 posts on one page, this takes about 0.3 secs to compile on my
> server.
>
> If I change the templates to:
>
> template 1:
> a typical post_block with {$vars} and {if expressions} in it
>
> template 2:
> {section name=items loop=$post_items}
> {include file="template1"}
> {/section}
>
> Now the page compiles in ~0.06 secs. Thats 5 times less than the
> {capture}-{eval} approach.
>
> Anyone who could clarify what's causing smarty to take so long to compile the
> first variant, please ?


because with eval the template has to be compiled everytime it is
displayed. with include the template is only compiled once and reused
every time it is accessed.

> Which one is to be preferred if the templates come from
> a db, and the number of db-queries is important for performance ?


if performance is a concern you never ever should use {eval}. it may
be acceptable when you have caching enabled but even then should be
taken with a grain of salt.

if you want to use template from a database, write a resource-plugin
for that: http://smarty.php.net/manual/en/template.resources.php


> Thanks in advance, Dennis.
>
> --
> Dennis Freise <cat@final-frontier.ath.cx>
> GnuPG key: 2DE8 CCEF 6E20 11D4 3B27 21EC B0BA 1749 D2C8 38ED
> Available at: http://www.final-frontier.ath.cx/?key-plain

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com