gpt4 book ai didi

php - microtime(true) - 无法测量 PHP 脚本执行时间

转载 作者:可可西里 更新时间:2023-10-31 22:53:28 25 4
gpt4 key购买 nike

在尝试比较 PHP 中的算法运行时间时,我遇到了 microtime() 函数。但我认为我在理解中遗漏了一些基本的东西。两次 microtime(true) 调用以秒为单位返回结果的区别,对吗?然后考虑这个极其简单的脚本:

$t1 =  microtime(true);
//do nothing
$t2 = microtime(true);

echo ($t2 - $t1);

当我多次运行此脚本时,我得到的值在 1.19 秒和 3.5 秒之间变化。这显然是错误的,因为页面重新加载是即时的,脚本绝对无事可做。

我做错了什么?

最佳答案

你一定是误读了结果,例如:

2.1457672119141E-6
  • 2.14 百万分之一秒,而不是 2.14 秒。

http://sandbox.onlinephpfunctions.com/code/5aa27a5fa9a228fd66eb08f0bb49384fc5b840d9

关于php - microtime(true) - 无法测量 PHP 脚本执行时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30962341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com