Guest User

Untitled

a guest
Oct 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. <?
  2.  
  3. /*
  4. * How to Use
  5. *
  6. * -- Create an empty time-holder array and add in start time
  7. * $t = array();
  8. * $t['start'] = microtime(true);
  9. * -- Do operation, then add in time afterwards
  10. * sleep(1);
  11. * $t['after_sleep'] = microtime(true);
  12. * -- Do other operations and add in times, then finally echo out the function
  13. * echo mini_bench_to($t);
  14. */
  15.  
  16. function mini_bench($arg_t, $arg_ra=false) {
  17. $tttime=round((end($arg_t)-$arg_t['start'])*1000,4);
  18. if ($arg_ra) $ar_aff['total_time']=$tttime;
  19. else $aff="total time : ".$tttime."ms\n";
  20. $prv_cle='start';
  21. $prv_val=$arg_t['start'];
  22.  
  23. foreach ($arg_t as $cle=>$val) {
  24. if($cle!='start') {
  25. $prcnt_t=round(((round(($val-$prv_val)*1000,4)/$tttime)*100),1);
  26. if ($arg_ra) $ar_aff[$prv_cle.' -> '.$cle]=$prcnt_t;
  27. $aff.=$prv_cle.' -> '.$cle.' : '.$prcnt_t." %\n";
  28. $prv_val=$val;
  29. $prv_cle=$cle;
  30. }
  31. }
  32. if ($arg_ra) return $ar_aff;
  33. return $aff;
  34. }
  35.  
  36. ?>
Add Comment
Please, Sign In to add comment