Home > php教程 > php手册 > body text

php记录代码执行时间(实现代码)

WBOY
Release: 2016-06-06 20:28:34
Original
1731 people have browsed it

本篇文章是对php记录代码执行时间的实现代码进行了详细的分析介绍,需要的朋友可以参考下

复制代码 代码如下:


$t1 = microtime(true);
// ... 执行代码 ...
$t2 = microtime(true);
echo '耗时'.round($t2-$t1,3).'秒';


简单说一下. microtime() 如果带个 true 参数, 返回的将是一个浮点类型. 这样 t1 和 t2 得到的就是两个浮点数, 相减之后得到之间的差. 由于浮点的位数很长, 或者说不确定, 所以再用个 round() 取出小数点后 3 位. 这样我们的目的就达到了~ ,香港虚拟主机,虚拟主机,香港服务器
Related labels:
php
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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template