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

Optimize Smarty Code

 
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
akbenutzer
Smarty n00b


Joined: 24 Sep 2019
Posts: 2

PostPosted: Wed Sep 25, 2019 5:54 am    Post subject: Optimize Smarty Code Reply with quote

Hello,

I want to improve my smarty code, and I need help if possible.

My Code:
Code:
{foreach name=merkmalfilter from=$Suchergebnisse->MerkmalFilter item=Merkmal}
{assign var=kMerkmal value=$Merkmal->kMerkmal}


I looked for phpbenchmarks and found this:
https://phpbench.com/
in the section
"Modify Loop: foreach() vs. for vs. while(list() = each())"
there is stated that the foreach loop can be fastened with a well written for loop.

My idea was to change my smarty code to this:
Code:
{assign var=key value=$Suchergebnisse->MerkmalFilter|@array_keys}
{assign var=size value=$key|@sizeof}
{$size}
{$key}
{for $i=1 to $size }
{assign var=kMerkmal value=$Suchergebnisse->MerkmalFilter->key->i}

But this is not working. Does somebody know the right way to do this?

Thank you.

Greetings Artur
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Wed Oct 02, 2019 9:17 pm    Post subject: Reply with quote

Did you profile your code?
Was that the slowest part of your whole program?
Back to top
View user's profile Send private message
akbenutzer
Smarty n00b


Joined: 24 Sep 2019
Posts: 2

PostPosted: Mon Oct 07, 2019 5:37 am    Post subject: Reply with quote

I do not know how to profile my code.

But i found my error and this code is now working. The time to load a specific page is now 1-2 sec faster than before.

This topic can be closed.
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