View previous topic :: View next topic |
Author |
Message |
v.laios Smarty Rookie
Joined: 15 Feb 2016 Posts: 8
|
Posted: Mon Feb 15, 2016 11:03 am Post subject: Smarty speed benchmark |
|
|
Hi i am using smarty in order to create dynamic data that later would be saved in a file. I upgraded smarty3 to the new version .28 and then to .29 and found smarty was 3 times slower that version .27. Here is a simple benchmark for all three versions using the simple query:
string: {if $price > 30}{math equation="x+y" x=$price y=20}{/if}
for a 100000 loop.
The results:
Smarty-27
Total: 9.2454550266266
One: 0.000092454550266266
Smarty-28
Total: 38.749762058258
One: 0.00038749762058258
Smarty-29
Total: 38.630138874054
One: 0.00038630138874054 |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Mon Feb 15, 2016 5:44 pm Post subject: Re: Smarty speed benchmark |
|
|
v.laios wrote: | Hi i am using smarty in order to create dynamic data that later would be saved in a file. |
I stopped reading here.
Do. Not. Do. It. |
|
Back to top |
|
v.laios Smarty Rookie
Joined: 15 Feb 2016 Posts: 8
|
Posted: Thu Feb 18, 2016 9:02 am Post subject: |
|
|
Why not? A lot of software uses this technic. And you havent tried to answer the question. You tried to avoid it. Nice job. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Thu Feb 18, 2016 11:42 am Post subject: |
|
|
I didn't avoid it.
I dismissed it as being idiotic.
Do not place business logic into templates. |
|
Back to top |
|
v.laios Smarty Rookie
Joined: 15 Feb 2016 Posts: 8
|
Posted: Thu Feb 18, 2016 3:34 pm Post subject: |
|
|
Sorry but i cannot understand. You mean that God said that i cannot use a tool the way i like it, but i have to use the way he likes because otherwise it is idiotic?
As a software engineer i can use anything that i like if i see fit. This is the way that things are being made. But off course god said otherwise.
So the thing very easy here. The new versions of Smarty are 3 times slower that the previous versions. So i wanted to know why? So forget about all else. THe question is simple. Why is smarty slower?
Can you please help me with this? |
|
Back to top |
|
CrazyTemplate Smarty Rookie
Joined: 12 Sep 2011 Posts: 31
|
Posted: Thu Feb 18, 2016 6:30 pm Post subject: |
|
|
v.laios, please don't feed the local troll
he is just another mean little person who replies to everyone that they are just wrong, without giving answers. just ignore him.
*edit*
I forgot to mention, that you should open a bug report here: http://www.smarty.net/forums/viewforum.php?f=5 |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Feb 18, 2016 10:28 pm Post subject: |
|
|
Try this in smarty 3, it has inline math:
string: {if $price > 30}{$price+20}{/if}
I'll let Uwe chime in on the speed specifics, I'm not sure why Smarty 3 versions would have such a difference. |
|
Back to top |
|
v.laios Smarty Rookie
Joined: 15 Feb 2016 Posts: 8
|
Posted: Mon Feb 22, 2016 1:20 pm Post subject: |
|
|
That happens when you write your first post and be welcomed by a troll. Next time i will carry my sword with me I have also posted it in bugs as noted!
Thanks for the answer. I will run the benchmark with the new code to see what happens and post here. |
|
Back to top |
|
v.laios Smarty Rookie
Joined: 15 Feb 2016 Posts: 8
|
Posted: Fri Feb 26, 2016 10:05 am Post subject: |
|
|
I have rerun the benchmarks with the new query and the results are the same:
Smarty-27
Total: 0.96813583374023
One: 0.000096813583374023
Smarty-28
Total: 3.4972178936005
One: 0.00034972178936005
Smarty-29
Total: 3.4825568199158
One: 0.00034825568199158
The new versions are 3 times slower as the old version |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Feb 26, 2016 11:21 pm Post subject: |
|
|
How did you loop over
Code: | {if $price > 30}{math equation="x+y" x=$price y=20}{/if} |
please provide that code as well.
Test with a profiler showed that Smarty 3 is executing the above mentioned line of code about 25% faster as Smarty 2.
So the time must be lost somehow by the code which does create the loop. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Feb 29, 2016 7:17 am Post subject: |
|
|
This has nothing to do with template inheritance at all.
Smarty 3 is object oriented and has much more features as Smarty 2. The payoff is that loading a template is slower as in Smarty 2.
So when loading a template in a loop and just execute one line of template code Smarty 2 will always win. |
|
Back to top |
|
v.laios Smarty Rookie
Joined: 15 Feb 2016 Posts: 8
|
Posted: Mon Feb 29, 2016 2:59 pm Post subject: |
|
|
This is done with fetch(string: ) but i dont mean between smarty 2 and 3 i mean between 3.27 and 3.28 and 3.29. The latest version of the code.
Here is the code
$smarty = new Smarty();
$loop = 0;
$speed = 100000;
$start = microtime(true);
$template = 'string: {if $price > 30}{math equation="x+y" x=$price y=20}{/if}';
$smarty->assign('price', '30');
for ($i=0; $i<$speed; $i++) {
$smarty->fetch($template);
$loop++;
}
$time = microtime(true) - $start;
echo "Total: " . $time . "<br />";
echo "One: " . ($time/$loop) . "<br />"; |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Feb 29, 2016 4:59 pm Post subject: |
|
|
What if you use a template file instead of a string? I have a hunch the compiler will need to evaluate and compile the template string on each invocation of the loop. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Mon Feb 29, 2016 5:54 pm Post subject: |
|
|
Okay have located the problem. I will come back with a solution ASAP |
|
Back to top |
|
|