In PHP, you can calculate the script execution time by using the built-in function microtime(), which can be used to return the current Unix timestamp in microseconds. The following article will show you how the microtime() function calculates script execution time.
The script execution time in PHP is actually the time required to execute the PHP script. To calculate script execution time, clock time is used instead of CPU execution time. Calculating the clock time before the script is executed and after the script is executed will help in calculating the script execution time.
Clock time can use the microtime() function. First use it before starting the script, then use it at the end of the script; finally using the formula (End_time - Start_time), you can calculate the execution time of the script.
Example:
Output:
Note: The microtime() function measures microseconds Returns the time in units; execution time is not fixed and depends on the processor.
The above is the entire content of this article, I hope it will be helpful to everyone's study. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !
The above is the detailed content of How to calculate script execution time in PHP. For more information, please follow other related articles on the PHP Chinese website!