|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
akbenutzer Smarty n00b
Joined: 24 Sep 2019 Posts: 2
|
Posted: Wed Sep 25, 2019 5:54 am Post subject: Optimize Smarty Code |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Oct 02, 2019 9:17 pm Post subject: |
|
|
Did you profile your code?
Was that the slowest part of your whole program? |
|
Back to top |
|
akbenutzer Smarty n00b
Joined: 24 Sep 2019 Posts: 2
|
Posted: Mon Oct 07, 2019 5:37 am Post subject: |
|
|
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 |
|
|
|
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
|