PHP Code Execution Timing Script


/ Published in: PHP
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.