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

php中microtime函数记录代码执行时间

WBOY
Release: 2016-06-13 11:19:17
Original
731 people have browsed it

简单说一下. microtime() 如果带个 true 参数, 返回的将是一个浮点类型. 这样 t1 和 t2 得到的就是两个浮点数, 相减之后得到之间的差. 由于浮点的位数很长, 或者说不确定, 所以再用个 round() 取出小数点后 3 位. 这样我们的目的就达到了~  

 

 代码如下 复制代码
$t1 = microtime(true);
// ... 执行代码 ...
$t2 = microtime(true);
echo '耗时'.round($t2-$t1,3).'秒';
简单说一下. microtime() 如果带个 true 参数, 返回的将是一个浮点类型. 这样 t1 和 t2 得到的就是两个浮点数, 相减之后得到之间的差. 由于浮点的位数很长, 或者说不确定, 所以再用个 round() 取出小数点后 3 位. 这样我们的目的就达到了~

 

microtime用法

microtime() 函数返回当前 Unix 时间戳和微秒数。

语法
microtime(get_as_float)参数 描述
get_as_float 如果给出了 get_as_float 参数并且其值等价于 TRUE,该函数将返回一个浮点数。

 


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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!