note 110608 added to function.microtime
| From: | Anonymus | Date: | Mon, 12 Nov 2012 17:59:34 +0000 |
| Subject: | note 110608 added to function.microtime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-191899@lists.php.net to get a copy of this message | ||
Skilled thought time and microtime returns different values because his test code sometimes says
they are different:
<?php
for ($i = 0; $i < 1000000; $i++)
{
if (time() < floor(microtime(true))) {
echo ".";
}
}
?>
But the problem is that the functions are not executed at the same time and therefor a change in
seconds can incur in meantime. Maybe it's more obvious if we write it like:
<?php
for ($i = 0; $i < 1000000; $i++)
{
$time1 = time();
$time2 = floor(microtime(true));
if ($time1 < $time2) {
echo ".";
}
}
?>
It should also be noted that getting the time costs time! So by measuring time your performance is
acctually worse. If it's noticable or not of course deppends on the code you are measuring and
how often you measure.
----
Server IP: 69.147.83.199
Probable Submitter: 213.185.179.163
----
Manual Page -- http://www.php.net/manual/en/function.microtime.php
Edit -- https://master.php.net/note/edit/110608
Del: integrated -- https://master.php.net/note/delete/110608/integrated
Del: useless -- https://master.php.net/note/delete/110608/useless
Del: bad code -- https://master.php.net/note/delete/110608/bad+code
Del: spam -- https://master.php.net/note/delete/110608/spam
Del: non-english -- https://master.php.net/note/delete/110608/non-english
Del: in docs -- https://master.php.net/note/delete/110608/in+docs
Del: other reasons-- https://master.php.net/note/delete/110608
Reject -- https://master.php.net/note/reject/110608
Search -- https://master.php.net/manage/user-notes.php