[SOLVED] Successive microtime(true) calls not correct
Posted: Fri Jun 29, 2007 9:55 pm
I'm playing with a benchmarking class I'm writing and having some issues with the value returned by microtime(true)
The problem is that when I subtract a value returned by microtime, from the previous value returned by microtime, sometimes the latter return value is smaller than the first. This is what I am assuming anyway.
See the following test.
What's up with this and how do I fix it?
The problem is that when I subtract a value returned by microtime, from the previous value returned by microtime, sometimes the latter return value is smaller than the first. This is what I am assuming anyway.
See the following test.
Code: Select all
<?php
class microtime_test
{
public function __construct()
{
$this->start_time = microtime(true);
}
public function test($pause = 0)
{
sleep($pause);
$new_time = microtime(true);
echo "Difference: " . ($new_time - $this->start_time) . "<br />";
$this->start_time = $new_time;
}
}
$mTest = new microtime_test();
for ($i = 0; $i < 5; $i++)
{
$mTest->test();
}
for ($i = 0; $i < 5; $i++)
{
$mTest->test(1);
}I can't test to see which one is larger, because they are always positive. They are also always of the same type.Difference: 4.1007995605469E-5
Difference: 3.4093856811523E-5
Difference: 1.1920928955078E-5
Difference: 1.0013580322266E-5
Difference: 9.0599060058594E-6
Difference: 1.0000469684601
Difference: 1.0001080036163
Difference: 1.0001060962677
Difference: 1.0001170635223
Difference: 1.0001058578491
What's up with this and how do I fix it?