note 110608 deleted from function.microtime by aharvey
| From: | aharvey@php.net | Date: | Tue, 13 Nov 2012 03:20:12 +0000 |
| Subject: | note 110608 deleted from function.microtime by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191904@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymus
----
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.