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

From: Date: Tue, 06 Jul 2004 16:12:47 +0000
Subject: Re: [SMARTY] Execution time of {eval ...}
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-11529@lists.php.net to get a copy of this message
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

« previous php.smarty.general (#11529) next »