PHP statistics time and memory usage examples share

Source: Internet
Author: User
Tags memory usage

  This article mainly introduces the PHP statistics time and memory usage example, we call the following method directly can be used, the need for friends can refer to the following

  Code as follows:/**  * record and statistical time (microseconds) and memory usage  * use method:  * <code>  * G (' begin '); Record start tag bit  *//... Interval Run code  * G (' End '); Record ends tab bit  * echo G (' Begin ', ' End ', 6); Statistical interval running time is accurate to 6 digits after the decimal  * echo G (' Begin ', ' End ', ' m '); Statistical interval Memory usage  * If the end marker bit is not defined, it is automatically  * with the current as a tag bit where the statistical memory usage requires MEMORY_LIMIT_ON constant to be true  * </code> & nbsp;* @param string $start start tag  * @param string $end end tag  * @param integer|string $dec decimal places or m   * @ Return mixed  */function G ($start, $end = ', $dec =4) {    static $_info       =   Array ( );     Static $_mem        =   Array ();     if (Is_float ($end)) {//record time         $_info[$start]  =   $end;    } ElseIf (!empty ($end)) {//Statistics time and memory usage         if (!isset ($_info[$end)) $_info[$end]       =  microtime (TRUE);         if (memory_limit_oN && $dec = = ' m ') {            if (!isset ($_mem[$end])) $_mem[$end]     = &NB Sp;memory_get_usage ();             return Number_format ($_mem[$end]-$_mem[$start])/1024);                  }else{            return num Ber_format (($_info[$end]-$_info[$start]), $DEC);        }             }else{//recording time and memory usage       &NB Sp $_info[$start]  =  microtime (TRUE);         if (memory_limit_on) $_mem[$start]           =  memory_get_usage ( );    }}  

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.