note 29531 added to function.microtime
| From: | salsi at icosaedro dot it | Date: | Sun, 16 Feb 2003 18:44:16 +0000 |
| Subject: | note 29531 added to function.microtime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44065@lists.php.net to get a copy of this message | ||
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");
--
http://www.php.net/manual/en/function.microtime.php
http://master.php.net/manage/user-notes.php?action=edit+29531
http://master.php.net/manage/user-notes.php?action=delete+29531
http://master.php.net/manage/user-notes.php?action=reject+29531