Copy codeThe Code is as follows:
/**
* Recording and statistical time (microseconds) and memory usage
* Usage:
* <Code>
* G ('begin'); // The start flag of the record.
* // Run the code in the... Interval
* G ('end'); // The end tag of the record.
* Echo G ('begin', 'end', 6); // the running time of the statistical interval is accurate to the last six digits of the decimal number.
* Echo G ('begin', 'end', 'M'); // calculates the memory usage in the interval.
* If the end tag is not defined, the current tag is automatically used as the tag.
* For memory usage statistics, the MEMORY_LIMIT_ON constant must be set to true.
* </Code>
* @ Param string $ start tag
* @ Param string $ end tag
* @ Param integer | string $ dec decimal point or m
* @ Return mixed
*/
Function G ($ start, $ end = '', $ dec = 4 ){
Static $ _ info = array ();
Static $ _ mem = array ();
If (is_float ($ end) {// record the time
$ _ Info [$ start] = $ end;
} Elseif (! Empty ($ end) {// 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 {// record time and memory usage
$ _ Info [$ start] = microtime (TRUE );
If (MEMORY_LIMIT_ON) $ _ mem [$ start] = memory_get_usage ();
}
}