marker[$name] = microtime(); } // END mark() // -------------------------------------------------------------------- /** * Calculates the time difference between two marked points. * * If the first parameter is empty this function instead returns the * {elapsed_time} pseudo-variable. This permits the the full system * execution time to be shown in a template. The output class will * swap the real value for this variable. * * @access public * @param string a paricular marked point * @param string a paricular marked point * @param integer the number of decimal places * @return mixed */ function elapsed_time($point1 = '', $point2 = '', $decimals = 4) { if ($point1 == '') { return '{elapsed_time}'; } if ( ! isset($this->marker[$point2])) $this->marker[$point2] = microtime(); list($sm, $ss) = explode(' ', $this->marker[$point1]); list($em, $es) = explode(' ', $this->marker[$point2]); return number_format(($em + $es) - ($sm + $ss), $decimals); } // END elapsed_time() // -------------------------------------------------------------------- /** * Auto Profiler * * This function cycles through the entire array of mark points and * matches any two points that are named identially (ending in "_start" * and "_end" respectively). It then compiles the execution times for * all points and returns it as an array * * @access public * @return array */ function auto_profiler() { $marker_keys = array_reverse(array_keys($this->marker)); $times = array(); foreach ($marker_keys as $val) { if (preg_match("/(.+?)_start/i", $val, $match)) { if (isset($this->marker[$match[1].'_end'])) { $times[$match[1]] = $this->elapsed_time($val, $match[1].'_end'); } } } return $times; } // -------------------------------------------------------------------- /** * Memory Usage * * This function returns the {memory_usage} pseudo-variable. * This permits it to be put it anywhere in a template * without the memory being calculated until the end. * The output class will swap the real value for this variable. * * @access public * @return string */ function memory_usage() { return '{memory_usage}'; } // END memory_usage() } // END CI_Benchmark class ?>