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 ( ); }}