Re: HTML_Template_Sigma again
| From: | Fabien MARTY | Date: | Wed, 26 Mar 2003 21:17:15 +0000 |
| Subject: | Re: HTML_Template_Sigma again | ||
| References: | 1 2 3 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-14648@lists.php.net to get a copy of this message | ||
> > I would like to make some benchs of your integrated cache solution...
>
> If you want to compare the performance of a built-in cache with a
> HTML_Template_ITX + Cache_Lite based solution (which I presume you want
> to do, as you are the lead developer of the latter)
> , you'd have to address the following:
> 1) 'Cache' is invalidated based on source file modification time. When I
> evaluated Cache_Lite usage, I found out that there is currently no easy
> way to mimic this behaviour, you'd have to write some new code (or
> borrow some from my implementation)
It's your choice :-)
> 2) You should also measure the time of parsing PHP code. Right now
> HTML_Template_Sigma.php is essentially the same size as
> HTML_Template_IT's three files.
I think that you don't understand the problem. When you use Cache_Lite, you include other
classes ONLY when the cache is not hit (have a look at the end of this tuto http://www.pearfr.org/index.php/en/article/cache_lite).
IT + Cache_Lite is definitively two times faster (or more...) because of this single line of
IT_Sigma :
require_once 'PEAR.php';
I have done a simple bench :
- a simple Template_Sigma script
- the same scripts encapsulted into Cache_Lite
'ab -c 10 -n 1000' gives the following result (on my linux box) :
- Template_Sigma only => 85 #/s
- Template_Sigma encapsulated into Cache_Lite => 270 #/s
Scripts are given at the end of this mail.
Yet, I had a look at Sigma code... IMHO, there is no cache system inside but a clever
"pre-compilation" of the template (like Smarty). Because you don't store the
resulting final html code but a "Sigma friendly state of the template".
So... Cache_Lite and Template_Sigma are not incompatible. But you have to precise that your cache is
more a precompilation than a real cache system.
Fab
---------------------- sigma only -------------------
<?php
$value = 'hello !';
require_once('HTML_Template_Sigma.php');
$tpl = new HTML_Template_Sigma('/home/fab/www/tests', '/tmp');
$tpl->setOption('trim_on_save', false);
$tpl->loadTemplatefile('test.tpl');
$tpl->setVariable('variable', $value);
$html = $tpl->get();
echo($html);
// The test.tpl file (template) is only a line :
// This is a template file . This is the value of variable : {variable}
?>
-----------------------------------------------------
----------------------- sigma into cache_lite -------
<?php
require_once('Cache/Lite.php');
$value = 'hello !';
$cache = new Cache_Lite();
if (!($html = $cache->get('sigma_'.$value))) {
require_once('HTML_Template_Sigma.php');
$tpl = new HTML_Template_Sigma('/home/fab/www/tests', '/tmp');
$tpl->setOption('trim_on_save', false);
$tpl->loadTemplatefile('test.tpl');
$tpl->setVariable('variable', $value);
$html = $tpl->get();
$cache->save($html);
}
echo($html);
// The test.tpl file (template) is only a line :
// This is a template file . This is the value of variable : {variable}
?>
-----------------------------------------------------