繁体   English   中英

计算运行某个功能所需的时间

[英]Calculate the time needed to run a certain function

我有可能吗? 例如。 如果我想测试str_replace()是否比preg_replace()更快?

简单的方法:

$time = microtime(true); // time in Microseconds

// Your code here

echo (microtime(true) - $time) . ' elapsed';

硬(呃)方式:使用代码分析器确切地了解您的方法需要多长时间。

您可以在脚本中运行相同的行10,000次(或更多),并使用microtime(true)来告诉它花费的时间:

microtime中()

我在这个帖子中找到了'bisko'的答案。

$ start = microtime(true);

for(...){....}

$ end = microtime(true);

echo($ end - $ start)。' 秒;

for循环可以替换为您想要的任何时间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM