When trying to compare the running time of an algorithm in PHP, I came across a function microtime(). But I think that there is something fundamental that I missed in understanding. The difference of the two calls microtime(true)returns the result in seconds, right? Then consider this extremely simple script:
$t1 = microtime(true);
//do nothing
$t2 = microtime(true);
echo ($t2 - $t1);
When I run this script several times, I get values from 1.19 seconds to 3.5 seconds. This is clearly wrong, as the page reload is instantaneous, and absolutely nothing needs to be done for the script.
What am I doing wrong?
source
share