note 83642 added to function.microtime
| From: | kpsimoulis | Date: | Thu, 05 Jun 2008 19:53:19 +0000 |
| Subject: | note 83642 added to function.microtime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140151@lists.php.net to get a copy of this message | ||
This function is very useful for putting a start and end point in your page to find out where is the
delay.
<?php
$start = microtime(true);
// My source code here
$end = microtime(true);
echo $end."-".$start."=".($end - $start). " seconds";
?>
If you try this example above (without any source code between the start and the end point). You
will get an ugly value, something like:
1212690530.4132-1212690530.4132=8.1062316894531E-6 seconds
You will wonder why you get this because both numbers seem to be equal. Well this is because there
is a hidden precision that we are not able to see.
To solve this problem I made a new function:
<?php
function my_microtime($precision = 4)
{
return round(microtime(true),4);
}
$start = microtime(true);
// My source code here
$end = microtime(true);
echo $end."-".$start."=".substr(($end - $start),0,5). " seconds";
?>
It would be useful if they add another parameter for precision in this function or at least another
boolean that will not include the hidden precision.
You can read more about the hidden precision in http://php.net/float
----
Server IP: 216.235.15.211
Probable Submitter: 69.70.39.58
----
Manual Page -- http://www.php.net/manual/en/function.microtime.php
Edit -- https://master.php.net/note/edit/83642
Del: integrated -- https://master.php.net/note/delete/83642/integrated
Del: useless -- https://master.php.net/note/delete/83642/useless
Del: bad code -- https://master.php.net/note/delete/83642/bad+code
Del: spam -- https://master.php.net/note/delete/83642/spam
Del: non-english -- https://master.php.net/note/delete/83642/non-english
Del: in docs -- https://master.php.net/note/delete/83642/in+docs
Del: other reasons-- https://master.php.net/note/delete/83642
Reject -- https://master.php.net/note/reject/83642
Search -- https://master.php.net/manage/user-notes.php