Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. <?php
  2. /**
  3. * Calculate a precise time difference.
  4. * @param string $start result of microtime()
  5. * @param string $end result of microtime(); if NULL/FALSE/0/'' then it's now
  6. * @return flat difference in seconds, calculated with minimum precision loss
  7. */
  8. function microtime_diff($start, $end = null) {
  9. if (!$end) $end = microtime();
  10.  
  11. list($start_usec, $start_sec) = explode(" ", $start);
  12. list($end_usec, $end_sec) = explode(" ", $end);
  13. $diff_sec = intval($end_sec) - intval($start_sec);
  14. $diff_usec = floatval($end_usec) - floatval($start_usec);
  15.  
  16. return floatval($diff_sec) + $diff_usec;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement