note 29531 rejected from function.microtime by didou
| From: | didou@php.net | Date: | Fri, 03 Oct 2003 16:50:18 +0000 |
| Subject: | note 29531 rejected from function.microtime by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57769@lists.php.net to get a copy of this message | ||
Note Submitter: salsi@icosaedro.it
----
To calculate the elapsed time with high precision, the example of the
manual page IS WRONG: floats can accomodate about only 14 digits,
while sec+usec require about 16 digits. So, my proposal:
function elapsed($start)
{
$end = microtime();
list($start2, $start1) = explode(" ", $start);
list($end2, $end1) = explode(" ", $end);
$diff1 = $end1 - $start1;
$diff2 = $end2 - $start2;
if( $diff2 < 0 ){
$diff1 -= 1;
$diff2 += 1.0;
}
return $diff2 + $diff1;
}
$start = microtime();
/* ... lot of code here ... */
$t = elapsed($start);
echo("elapsed time = $t seconds\n");