I'm trying to use php's microtime() to benchmark how long two loops in my code take, to see which one runs faster. Here's my code:
$now = microtime();
//loop1 here
$elapsed = microtime() - $now;
echo "Elapsed: $elapsed <br />";
When I run this for one loop, I get the result in negative numbers, something like:
Elapsed: -0.120572
This is strange, since microtime()
should always be bigger than its value a few microseconds earlier?
For the second loop, the value is always positive:
Elapsed: 0.005483
What's going on here?
根据http://au1.php.net/manual/en/function.microtime.php使用microtime(true)
as false 将 microtime 作为字符串返回,并且您在字符串上执行数学运算而不是作为数字..
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.