发布日期:2018-03-26
如何精确测量php某段代码的执行时间+ 查看更多
如何精确测量php某段代码的执行时间
+ 查看更多
发布日期:2018-03-26 14:19
分类:PHP
浏览次数:128
例如,我想知道执行一个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函数。从文档
http://php.net/microtime
microtime — Return current Unix timestamp with microseconds(返回当前Unix微秒时间戳)用法示例:
$start = microtime(true); while (...) { } $time_elapsed_secs = microtime(true) - $start;