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

Smarty speed benchmark
Goto page 1, 2  Next
 
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
v.laios
Smarty Rookie


Joined: 15 Feb 2016
Posts: 8

PostPosted: Mon Feb 15, 2016 11:03 am    Post subject: Smarty speed benchmark Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Feb 15, 2016 5:44 pm    Post subject: Re: Smarty speed benchmark Reply with quote

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
View user's profile Send private message
v.laios
Smarty Rookie


Joined: 15 Feb 2016
Posts: 8

PostPosted: Thu Feb 18, 2016 9:02 am    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Feb 18, 2016 11:42 am    Post subject: Reply with quote

I didn't avoid it.
I dismissed it as being idiotic.
Do not place business logic into templates.
Back to top
View user's profile Send private message
v.laios
Smarty Rookie


Joined: 15 Feb 2016
Posts: 8

PostPosted: Thu Feb 18, 2016 3:34 pm    Post subject: Reply with quote

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
View user's profile Send private message
CrazyTemplate
Smarty Rookie


Joined: 12 Sep 2011
Posts: 31

PostPosted: Thu Feb 18, 2016 6:30 pm    Post subject: Reply with quote

v.laios, please don't feed the local troll Wink

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
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Feb 18, 2016 10:28 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
v.laios
Smarty Rookie


Joined: 15 Feb 2016
Posts: 8

PostPosted: Mon Feb 22, 2016 1:20 pm    Post subject: Reply with quote

That happens when you write your first post and be welcomed by a troll. Next time i will carry my sword with me Smile 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
View user's profile Send private message
v.laios
Smarty Rookie


Joined: 15 Feb 2016
Posts: 8

PostPosted: Fri Feb 26, 2016 10:05 am    Post subject: Reply with quote

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 Sad
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Fri Feb 26, 2016 11:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat Feb 27, 2016 11:47 am    Post subject: Reply with quote

The problem is in Smarty 3 before and after inheritance changes.
http://www.rootdir.org/.offload/Smarty-eq-20160227.rar

composer update
./init.php
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Feb 29, 2016 7:17 am    Post subject: Reply with quote

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
View user's profile Send private message
v.laios
Smarty Rookie


Joined: 15 Feb 2016
Posts: 8

PostPosted: Mon Feb 29, 2016 2:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Feb 29, 2016 4:59 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Mon Feb 29, 2016 5:54 pm    Post subject: Reply with quote

Okay have located the problem. I will come back with a solution ASAP
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
Goto page 1, 2  Next
Page 1 of 2

 
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