note 110633 rejected from function.microtime by googleguy
| From: | googleguy@php.net | Date: | Thu, 15 Nov 2012 17:45:54 +0000 |
| Subject: | note 110633 rejected from function.microtime by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192000@lists.php.net to get a copy of this message | ||
Note Submitter: m.milovanovic at google's mail
----
time() and microtime() return consecutive times as obtained from execution engine. Some microseconds
elapse between these two events and that's what an observer sees as a different return times.
code to test this (although it still has some overhead, i'll assume that it's good enough
for demonstration purposes)
for ($i = 0; $i < 1000000; $i++)
{
$time = time()."|".microtime();//these two calls should happen as close as possible,
and concatenation might spend some time (consecutive variable value assignment will spend even more
time, on my computer, twice as much at best)
$parts = explode("|", $time);
$parts[1] = implode(".", array(end(explode(" ", $parts[1])),
end(explode(".", reset(explode(" ", $parts[1]))))));//making precise microtime
if($parts[0] < floor($parts[1])) {
echo "time() returned: $parts[0]\n<br/>microtime() returned:
$parts[1]\n\n<br/><br/>";
}
}