The execution time of PHP scripts is often calculated based on the execution time of PHP scripts to learn about the efficiency of scripts. For example, if there is a large segment of PHP script, we need a method to obtain the script execution time in segments. First, we will introduce the functions to be used: the split function is not recommended in the timing function PHP5.5, and the function is slightly modified.
The execution time of PHP scripts is often calculated based on the execution time of PHP scripts to learn about the efficiency of scripts. For example, if there is a large segment of PHP script, we need a method to obtain the script execution time in segments. First, we will introduce the functions to be used: // timing functions // In PHP5.5, we do not recommend using the split function, but slightly modify the function.
The execution time of the PHP script is calculated in segments.
In many cases, we need to calculate the execution time of PHP scripts to learn about the efficiency of scripts and other issues. For example, if there is a large segment of PHP script, we need a method to obtain the script execution time in segments. First, we will introduce the functions to be used:
// The split function is not recommended in the timing function // PHP5.5. slightly modify the function runtime ($ mode = 0) {static $ t; if (! $ Mode) {$ t = microtime (); return ;}$ t1 = microtime (); $ arr_t0 = explode ("", $ t ); $ arr_t1 = explode ("", $ t1); return sprintf ("%. 3f ms ", (array_sum ($ arr_t1)-array_sum ($ arr_t0) * 1000);} runtime (); // start time/* // PHP script to be calculated $ result = 0; for ($ I = 0; $ I <100; $ I ++) {$ result + = $ I;} echo $ result; */echo runtime (1); // The timer ends and the timer result runtime () is output (); // start time/* // PHP script to be calculated $ result = 0; for ($ I = 0; $ I <100; $ I ++) {$ result + = $ I;} echo $ result; */echo runtime (2); // The timer ends and outputs the timer result.
Original article address: calculates the execution time of PHP scripts in segments. Thanks to the original author for sharing.