Posted By

anagaiyahoocom on 03/29/12


Tagged

php


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Priestd09


PHP Code Execution Timing Script


 / Published in: PHP
 

Place startTime() at beginning where timing is to start. Get the return value and set the start time variable. At end of script to time call execTime($start) passing the start time and this will calculate elapsed time of execution.

  1. function startTime() {
  2. $mtime = microtime();
  3. $mtime = explode(' ', $mtime);
  4. $secs = $mtime[1] + $mtime[0];
  5. return $secs;
  6. }
  7.  
  8. function execTime($start) {
  9. $end = startTime();
  10. $total = $end - $start;
  11. return '<Br>'.sprintf('Executed in %.6f seconds.', $total);
  12. }
  13.  
  14. //Usage
  15.  
  16. $start = startTime();
  17.  
  18. //the code.....
  19.  
  20. echo execTime($start);

Report this snippet  

You need to login to post a comment.