Need a mini benchmark ?
Use microtime with this (very smart) benchmark function :
mixed mini_bench_to(array timelist[, return_array=false])
return a mini bench result
-the timelist first key must be 'start'
-default return a resume string, or array if return_array= true :
'total_time' (ms) in first row
details (purcent) in next row
example :
<?php
unset($t); $t['start'] = microtime(true);
$tab_test=array(1,2,3,4,5,6,7,8);
$fact=1;
$t['init_values'] = microtime(true);
foreach ($tab_test as $key=>$value)
{
$fact=$fact*$value;
}
$t['loop_fact'] = microtime(true);
echo "fact = ".$fact."\n";
echo "---- string result----\n";
$str_result_bench=mini_bench_to($t);
echo $str_result_bench; echo "---- tab result----\n";
$tab_result_bench=mini_bench_to($t,true);
echo var_export($tab_result_bench,true);
?>
this example return:
---- string result----
total time : 0.0141 ms
start -> init_values : 51.1 %
init_values -> loop_fact : 48.9 %
---- tab result----
array (
'total_time' => 0.0141,
'start -> init_values' => 51.1,
'init_values -> loop_fact' => 48.9,
)
The function to include :
<?php
function mini_bench_to($arg_t, $arg_ra=false)
{
$tttime=round((end($arg_t)-$arg_t['start'])*1000,4);
if ($arg_ra) $ar_aff['total_time']=$tttime;
else $aff="total time : ".$tttime."ms\n";
$prv_cle='start';
$prv_val=$arg_t['start'];
foreach ($arg_t as $cle=>$val)
{
if($cle!='start')
{
$prcnt_t=round(((round(($val-$prv_val)*1000,4)/$tttime)*100),1);
if ($arg_ra) $ar_aff[$prv_cle.' -> '.$cle]=$prcnt_t;
$aff.=$prv_cle.' -> '.$cle.' : '.$prcnt_t." %\n";
$prv_val=$val;
$prv_cle=$cle;
}
}
if ($arg_ra) return $ar_aff;
return $aff;
}
?>