note 91566 added to function.microtime

From: Date: Wed, 17 Jun 2009 10:32:46 +0000
Subject: note 91566 added to function.microtime
Groups: php.notes 
Request: Send a blank email to php-notes+get-156958@lists.php.net to get a copy of this message
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); // if previous used //-- zone to bench $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"; //-- END zone to bench echo "---- string result----\n"; $str_result_bench=mini_bench_to($t); echo $str_result_bench; // string return 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; } ?> ---- Server IP: 89.31.146.176 Probable Submitter: 88.175.247.53 ---- Manual Page -- http://www.php.net/manual/en/function.microtime.php Edit -- https://master.php.net/note/edit/91566 Del: integrated -- https://master.php.net/note/delete/91566/integrated Del: useless -- https://master.php.net/note/delete/91566/useless Del: bad code -- https://master.php.net/note/delete/91566/bad+code Del: spam -- https://master.php.net/note/delete/91566/spam Del: non-english -- https://master.php.net/note/delete/91566/non-english Del: in docs -- https://master.php.net/note/delete/91566/in+docs Del: other reasons-- https://master.php.net/note/delete/91566 Reject -- https://master.php.net/note/reject/91566 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#156958) next »