Quote:
Originally Posted by snoopytas
The render uses 'eval' 'nuff said
Kym
|
OK, but I ran this modified version of the benchmark:
PHP Code:
require('./global.php');
require(DIR . '/includes/adminfunctions_template.php');
$vbulletin->options['addtemplatename'] = 0;
$vbulletin->templatecache['text_bit'] = compile_template('{vb:raw text}');
$vbulletin->templatecache['text'] = compile_template('{vb:raw textbits}');
$vbulletin->templatecache['text_foreach'] = compile_template('<vb:each from="textbits" value="text">{vb:raw text}</vb:each>');
// Benchmarking bit templates
$start = microtime(true);
$textbits ='';
for ($i = 1; $i < 10000; $i++)
{
//$templater = vB_Template::create('text_bit');
//$templater->register('text', 'This is Text #' . $i);
//$textbits .= $templater->render();
$text = 'This is Text #' . $i;
eval($vbulletin->templatecache['text_bit']);
$textbits .= $final_rendered;
}
$templater = vB_Template::create('text');
$templater->register('textbits', $textbits);
$result1 = trim($templater->render());
$end = microtime(true);
header('Content-type: text/plain');
echo('Time taken for 10.000 Bit Templates: ' . ($end-$start) . "\n");
// Benachmarking <vb:each>
$start = microtime(true);
$textbits = array();
for ($i = 1; $i < 10000; $i++)
{
$textbits[] = 'This is Text #' . $i;
}
$templater = vB_Template::create('text_foreach');
$templater->register('textbits', $textbits);
$result2 = trim($templater->render());
$end = microtime(true);
echo('Time taken for 10.000 Array-Elements with <vb:each>: ' . ($end-$start) . "\n");
if ($result1 == $result2)
{
echo('Success - Both methods yielded the same result data');
}
else
{
echo('Huh? Smth. went wrong, the results are not identical');
echo("\n\n----\n$result1\n----\n$result2");
}
and I got these results:
Code:
Time taken for 10.000 Bit Templates: 0.072948932647705
Time taken for 10.000 Array-Elements with <vb:each>: 0.011199951171875
Success - Both methods yielded the same result data
vs. these for the original version:
Code:
Time taken for 10.000 Bit Templates: 1.542927980423
Time taken for 10.000 Array-Elements with <vb:each>: 0.011492967605591
Success - Both methods yielded the same result data
That's 6.5 times slower vs 134 times slower, and seems to indicate that eval() isn't the main offender.