Microtime (true) - Incorrect measurement of PHP script runtime

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?

+4
source share
2 answers

Calculations (with get_as_float as true) will give you results in seconds, according to the PHP documentation.

microtime() "msec sec", sec - Unix (0:00:00 1 1970 ) msec , .

get_as_float TRUE, microtime() float, Unix .

. http://php.net/manual/en/function.microtime.php

, .

+1

All Articles