While trying to compare algorithm running time in PHP, I came across the microtime()
function. But I think there's something fundamental I've missed in understanding. The difference of two microtime(true)
calls 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 varying between 1.19 seconds and 3.5 seconds. This is clearly wrong, as the page reload is instant and there's absolutely nothing for the script to do.
What am I doing wrong?