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 * ...