<?php
include_once("cls_ft.php");
$start=microtime();
//get the ft object
$ft=new FastTemplate(".");
//define template files.
$ft->define(array('main'=>'a_mixed.html','row' => 'b_mixed.html'));
//define a dynamic block in "row" template
$ft->define_dynamic('c_row','row');
$z=0;
//parse the 5000 rows in a for loop and assign some values
for($i=1;$i<=50;$i++)
{
for($j=1;$j<=100;$j++)
{
$ft->assign('C','dynamic_row:'.$j);
//now parse the "c_row" in "append" mode.
//this is done by adding a "."(dot) in front of "c_row" block
//we send the output to 'C_OUT'.This tag will be created by the engine
//in the "row" template.When you parse he's parent("row") the assignation is
//done automaticaly.
$ft->parse('C_OUT','.c_row');
$z++;
}
$ft->assign('CELL_TEXT',"row:.$i");
//now parse the row in "append" mode.
//this is done by adding a "."(dot) in front of "row" template
//we send the output to TABLE_ROWS,the tag from the "main" template
$ft->parse('TABLE_ROWS','.row');
//we now must clear the 'C_OUT' else we get a very big......... result:)
$ft->clear('C_OUT');
$z++;
}
//now assign all values for the "main" template and parse this too.
$ft->assign('HEADER','Two static templates and one dynamic block, 5000 rows test');
$ft->parse('MAIN_CONTENT','main');
$end=microtime();
echo "Printed $z row(s) in ".microtime_diff($end,$start)." secconds<br>";
//print the content
$ft->ft_print('MAIN_CONTENT');
function microtime_diff($a,$b) {
list($a_micro, $a_int)=explode(' ',$a);
list($b_micro, $b_int)=explode(' ',$b);
if ($a_int>$b_int) {
return ($a_int-$b_int)+($a_micro-$b_micro);
} elseif ($a_int==$b_int) {
if ($a_micro>$b_micro) {
return ($a_int-$b_int)+($a_micro-$b_micro);
} elseif ($a_micro<$b_micro) {
return ($b_int-$a_int)+($b_micro-$a_micro);
} else {
return 0;
}
} else { // $a_int<$b_int
return ($b_int-$a_int)+($b_micro-$a_micro);
}
}
?>