note 83527 modified in function.microtime by felipe
| From: | felipe@php.net | Date: | Fri, 30 May 2008 11:30:39 +0000 |
| Subject: | note 83527 modified in function.microtime by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-140000@lists.php.net to get a copy of this message | ||
This function allows you to easily calculate time difference between two points in time without
losing the precision.
<?php
/** Calculate a precise time difference.
@param string $start result of microtime()
@param string $end result of microtime(); if NULL/FALSE/0/'' then it's now
@return flat difference in seconds, calculated with minimum precision loss
*/
function microtime_diff( $start, $end=NULL ) {
if( !$end ) {
$end= microtime();
}
list($start_usec, $start_sec) = explode(" ", $start);
list($end_usec, $end_sec) = explode(" ", $end);
$diff_sec= intval($end_sec) - intval($start_sec);
$diff_usec= floatval($end_usec) - floatval($start_usec);
return floatval( $diff_sec ) + $diff_usec;
}
?>
--was--
This function allows you to easily calculate time difference between two points in time without
losing the precision.
/** Calculate a precise time difference.
@param string $start result of microtime()
@param string $end result of microtime(); if NULL/FALSE/0/'' then it's now
@return flat difference in seconds, calculated with minimum precision loss
*/
function microtime_diff( $start, $end=NULL ) {
if( !$end ) {
$end= microtime();
}
list($start_usec, $start_sec) = explode(" ", $start);
list($end_usec, $end_sec) = explode(" ", $end);
$diff_sec= intval($end_sec) - intval($start_sec);
$diff_usec= floatval($end_usec) - floatval($start_usec);
return floatval( $diff_sec ) + $diff_usec;
}
http://php.net/manual/en/function.microtime.php