gpt4 book ai didi

php - 测量php脚本执行时间的准确方法

转载 作者:IT老高 更新时间:2023-10-28 11:38:39 25 4
gpt4 key购买 nike

我想知道 PHP for 循环执行需要多少毫秒。

我知道通用算法的结构,但不知道如何在 PHP 中实现它:

Begin
init1 = timer(); // where timer() is the amount of milliseconds from midnight
the loop begin
some code
the loop end
total = timer() - init1;
End

最佳答案

您可以使用 microtime为此发挥作用。来自 the documentation :

microtime — Return current Unix timestamp with microseconds


If get_as_float is set to TRUE, then microtime() returns a float, which represents the current time in seconds since the Unix epoch accurate to the nearest microsecond.

示例用法:

$start = microtime(true);
while (...) {

}
$time_elapsed_secs = microtime(true) - $start;

关于php - 测量php脚本执行时间的准确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6245971/

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