PHP statistics time and memory usage sample sharing _php Tutorial

Source: Internet
Author: User
Copy CodeThe code is as follows:
/**
* Recording and statistical time (microseconds) and memory usage
* How to use:
*
* G('begin'); // 记录开始标记位
* // ... 区间运行代码
* G('end'); // 记录结束标签位
* echo G('begin','end',6); // 统计区间运行时间 精确到小数后6位
* echo G('begin','end','m'); // 统计区间内存使用情况
* 如果end标记位没有定义,则会自动以当前作为标记位
* 其中统计内存使用需要 MEMORY_LIMIT_ON 常量为true才有效
*

* @param string $start start tag
* @param string $end end tag
* @param integer|string $dec decimal digits 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] = Memory_get_usage ();
Return Number_format (($_mem[$end]-$_mem[$start])/1024);
}else{
Return Number_format (($_info[$end]-$_info[$start]), $DEC);
}

}else{//recording time and memory usage
$_info[$start] = Microtime (TRUE);
if (memory_limit_on) $_mem[$start] = Memory_get_usage ();
}
}

http://www.bkjia.com/PHPjc/741258.html www.bkjia.com true http://www.bkjia.com/PHPjc/741258.html techarticle Copy the code as follows:/** * Recording and Statistics time (microseconds) and memory usage * Use method: * code * G (' begin ');//record start tag bit *//... Interval Run code * ...

  • Related Article

    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.