Home >Backend Development >PHP Tutorial >Microtime function in PHP records code execution time_PHP tutorial

Microtime function in PHP records code execution time_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:03:101268browse

To put it simply, if microtime() takes a true parameter, it will return a floating point type. In this way, t1 and t2 will get two floating point numbers, and the difference will be obtained after subtracting them. Since the number of floating point digits is very small, long, or uncertain, so we use round() to take out 3 digits after the decimal point. In this way, our goal is achieved~ ​

 代码如下 复制代码
$t1 = microtime(true);
// ... 执行代码 ...
$t2 = microtime(true);
echo '耗时'.round($t2-$t1,3).'秒';
To put it simply, if microtime() takes a true parameter, it will return a floating point type. In this way, t1 and t2 will get two floating point numbers, and the difference will be obtained after subtracting them. Since the number of floating point digits is very small, long, or uncertain, so we use round() to take out 3 digits after the decimal point. In this way, our goal is achieved~

microtime usage

The microtime() function returns the current Unix timestamp and microseconds.

Grammar
microtime(get_as_float) parameter description
get_as_float If the get_as_float parameter is given and its value is equivalent to TRUE, this function returns a floating point number.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445305.htmlTechArticleSimply say. If microtime() takes a true parameter, the returned value will be a floating point type. In this way t1 What you get with t2 is two floating point numbers, and you get the difference after subtracting them. Since floating point...
Statement:
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