Home>Article>Backend Development> How to calculate program running time in php
1. Functions used
a. Use the functionmicrotime ()
microtime ( bool $get_as_float = ? ) : mixed
$get_as_float
which can be omitted when set toTRUE
When , it is specified that the function should return a floating point number, otherwise it returns a string. Default is FALSE.
Return value: Default return string , wheresec
is the sinceUnix
epoch (0:00:00 January 1, 1970 GMT) The number of seconds since,microsec
is the microsecond part. If the argument is set toTRUE
, returns a floating point number representing the current time in seconds since theUnix
epoch, accurate to microseconds.
b. Use the functionexplode()
explode(separator,string,limit)
separator to specify where to split characters string.
string The string to be split.
limit specifies the number of array elements returned (optional)
2. The code is as follows :
3. Output:
0.58607300 1617257726本网页执行耗时:0.017 秒。1617257726
PS: For the sake of neatness of the program, we can use this code This function can also be achieved by writing it as a class, introducing it when used, instantiating the class before the program starts, and calling a method at the end.
Recommendation:《2021 PHP interview questions summary (collection)》《php video tutorial》
The above is the detailed content of How to calculate program running time in php. For more information, please follow other related articles on the PHP Chinese website!