Home > Backend Development > PHP Tutorial > Share the execution time of a PHP code, accurate to the microsecond level

Share the execution time of a PHP code, accurate to the microsecond level

WBOY
Release: 2016-07-28 08:26:33
Original
1347 people have browsed it
<span>function  </span><span>microtime_float </span><span>()
</span><span>{
</span><span>list</span><span>( </span><span>$usec </span><span>,  </span><span>$sec </span><span>) </span><span>=  </span><span>explode </span><span>( </span><span>" " </span><span>,  </span><span>microtime </span><span>());
</span><span>$sec</span><span>=(string)</span><span>$sec</span><span>;
</span><span>$sec</span><span>=</span><span>substr</span><span>(</span><span>$sec</span><span>,</span><span>-</span><span>4</span><span>);
</span><span>return </span><span>(</span><span>(float) </span><span>$sec </span><span>+(float)</span><span>$usec</span><span>);
</span><span>}
这段代码只能计算到时间戳后四位的结果,大概就是一小时之内的执行时间,想要检测更多的话,只要
修改substr中的截取的长度,但是要注意哈,float最大只支持14位哦。
</span>
Copy after login

The above has introduced the execution time of sharing a PHP code, accurate to the microsecond level, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template