The execution time of the PHP script is calculated in segments.

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.