Home >Backend Development >PHP Tutorial >Microtime function in PHP records code execution time_PHP tutorial
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).'秒'; |
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.