1<?phpif( !defined(' BasePath '))Exit(' No Direct script access allowed ');2 // ------------------------------------------------------------------------3 4 /**5 * CodeIgniter Benchmark Class6 */7 classCi_benchmark {8 9 /**Ten * List of all benchmark markers and when they were added One */ A var $marker=Array(); - - // -------------------------------------------------------------------- the - /** - * Set A benchmark marker - */ + functionMark$name) - { + //This method is very simple, that is, when invoking local law anywhere in the program, the current point in time is recorded. A $this->marker[$name] =Microtime(); at } - - // -------------------------------------------------------------------- - - /** - * Calculates the time difference between and marked points. in * Calculates the time between two points in time. - */ to functionElapsed_time ($point 1= ",$point 2= ",$decimals= 4) + { - /* the * If no definite point of time is given, then the time of the entire program is calculated. * * How can we calculate the running time of the whole program? In fact, this calculation is performed by the output component. $ * While calling Benchmark::elapsed_time (); (no arguments), essentially returning the first is notPanax Notoginseng * The entire program run time, also impossible to do, in essence, return is a {elapsed_time} tag, and then - * Output will calculate the entire program run time when processing the outputs, as the process output stage can be considered the * To be in the final phase, you can approximate the total time and then replace {elapsed_time} in the output. + * the following memory_usage () principle is the same. A * See: The _display () method in core/output.php. the */ + if($point 1= = "') - { $ return' {elapsed_time} '; $ } - - if( !isset($this->marker[$point 1])) the { - return‘‘;Wuyi } the - if( !isset($this->marker[$point 2])) Wu { - $this->marker[$point 2] =Microtime(); About } $ - //Why this list is used here is because Microtime (); The return value is the format of "msec sec". - List($SM,$ss) =Explode(‘ ‘,$this->marker[$point 1]); - List($em,$es) =Explode(‘ ‘,$this->marker[$point 2]); A + return Number_format(($em+$es) - ($SM+$ss),$decimals); the } - $ // -------------------------------------------------------------------- the the /** the * Memory Usage the */ - functionmemory_usage () in { the //Output::_display (); the return' {memory_usage} '; About } the the}
VII) CodeIgniter Source code Analysis of the benchmark.php