Location: PHPKode > scripts > ft classes > ft-classes/test_unit_b.php
<?php
//here is a quick sample and benchmark for a nested dymaick block in one file
include_once('cls_ft.php');
//include_once('cls_ft.php');
$start=microtime();
//create the class object and set the root path
$ft=new ft('.');
//define one template file
$ft->define(array('main' => 'b_dynamic.html'));
//define the dynamic block inside the 'main' template
$ft->define_dynamic('a_row','main');
//nested dynamic block(inside the a_row) 
$ft->define_dynamic('b_row','a_row');


$z=0;
//do a 500 rows loop for the first block and assign $i to a tag... 
for($i=1;$i<=50;$i++)
{
    for($j=1;$j<=100;$j++)
    {
        $ft->assign('C','b_row'.$j);
        $ft->parse('BROW_OUT','.b_row');
        $z++;
    }
    $ft->assign('NESTED_HEADER','Nested Block '.$i);
    $ft->assign('B',"row:$i");
    $ft->parse('AROW_OUT','.a_row');
    //clean out the BROW_OUT content
    $ft->clear('BROW_OUT');
   $z++;
}

$ft->assign('A','5000  nested dynamic block test');
//parse the template.
$ft->parse('MAIN','main');
$end=microtime();
echo "Printed $z rows in ".microtime_diff($end,$start);
//print and get back here
$ft->ft_print('MAIN');


/**
 * @return float
 * @param a string
 * @param b string
 * @desc (From php manual) compute the microtime diff format.
 */
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);
     }
  }

?>
Return current item: ft classes