Re: Reduce execution time in loops
| From: | Andrei Zmievski | Date: | Wed, 05 Dec 2001 22:28:17 +0000 |
| Subject: | Re: Reduce execution time in loops | ||
| References: | 1 2 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-2156@lists.php.net to get a copy of this message | ||
On Wed, 05 Dec 2001, Victor Boivie wrote:
> That will depend very much on how your benchmark file looks like. I
> was looping through a big array and there isn't much other code or
> HTML at all inside the {section}, so those 4 lines were quite
> important to get rid.
>
> Of course, this is not at all the case for most project, so my gain of
> 45 percent (not 80) was perhaps just a lucky shot.
>
> Maybe there isn't a need at all for a manual optimization of the
> {section} tag as I proposed first. But in the next major version I
> would like the Smarty compiler to optimize the code like a real
> compiler, if possible. I know that it would really be a good feature.
I can do some optimizations right away -- having Smarty not output those
5 lines by default, but whenever %section.first% or
$smarty.section.first is mentioned it would compile into the needed PHP
code. There is a flip side though, if you use
first/last/index_prev/index_next/rownum in multiple places inside the
loop, it would be less efficient than computing them once and storing
them in section props. Is this optimization worth it? It all depends on
your particular situation I guess.
-Andrei
Give a man a fish; you have fed him for today. Teach a man to fish;
and you can sell him fishing equipment.
-Author unknown