Speed.
Well, i won’t bother to attack the fact that it takes time to parse and compile smarty-code into PHP — since Smarty caches the result anyway.
It (sadly) takes time to include and parse PHP-code, so on heavy sites you may want to keep it on a minimum. Obviously, Smarty contains a lot of code to parse and handle all it’s magic, which slows it down. Let’s make some simple tests.
benchmark-smarty-include.php:
Codice PHP:
<? include_once( '/usr/share/php/smarty/libs/Smarty.class.php' ); ?>
<? print 'Hello world!'; ?>
As you see, we don’t actually do anything with Smarty, we just include it. Now, lets see how fast this goes:
The command i run:
ab -c 10 -n 100 http://localhost/benchmark-smarty-include.php
*snip*
Requests per second: 49.23 [#/sec] (mean)
Time per request: 203.112 [ms] (mean)
*snip*
And using our engine created in the examples below, benchmark-smarter-include.php:
Codice PHP:
<? include_once( 'smarter.php' ); ?>
<? print 'Hello world!'; ?>
Again, we don’t do anything. The class just gets declared.
Apache benchmark, with the same parameters gives us..:
*snip*
Requests per second: 423.35 [#/sec] (mean)
Time per request: 23.621 [ms] (mean)
*snip*
Now, how about that! The script which includes Smarty uses 179.491 milliseconds more than our small template engine which uses PHP! Thats not good..
The tests was runned on a basic linux+apache2+php5 installation (my laptop), without any accelerator.