_timer = new Zeed_Util_Timer(false); $this->_timeStart = microtime(); $head = ' '; /* * 初始化时先把头部压入栈中 */ array_push($this->_content, $head); } /** * 克隆解释器 */ private function __clone() { } protected function output($str) { $this->_message .= $str; } /** * 获取注册表实例对象 * * * $__instance = getInstance(); * * * @return object core_registry */ public static function getInstance() { if (null === self::$_instance) { self::$_instance = new self(); } return self::$_instance; } public function start($message = '') { // $colors = array('#E54646','#EE7C6B','#F5A89A','#FCDAD5'); // static $i = 150, $j = 0, $k = 0; // $i += 10; // $j += 1; // $k += 30; /* * 消息开始时把消息头压入栈中 */ array_push($this->_content, $this->_prevMessages . '
' . $message . '
'); // array_push($this->_content, // $this->_prevMessages . // '
' . $message . '
'); $this->_prevMessages = ''; if (function_exists('memory_get_usage')) { $this->_memoryBefore[] = memory_get_usage(); } /* * 计数器重设 */ $this->_timer->reset(); $this->_timeBefore[] = $this->_timer->start(); } public function stop($add_total = true) { $time_after = $this->_timer->stop(); $timestart = (!defined('TIMESTART')) ? $this->_timeStart : TIMESTART; $pagestart = explode(' ', $timestart); $pagestart = $pagestart[0] + $pagestart[1]; $time_before = array_pop($this->_timeBefore); $time_before = $time_before - $pagestart; $time_after = $time_after - $pagestart; $time_taken = $time_after - $time_before; if ($add_total) { $this->_timeTotal += $time_taken; } $this->output("

Time Before: " . number_format($time_before, 5) . " seconds
"); $this->output("Time After: " . number_format($time_after, 5) . " seconds
"); $this->output("Time Taken: " . number_format($time_taken, 5) . " seconds

"); if (function_exists('memory_get_usage')) { $memory_before = array_pop($this->_memoryBefore); $memory_after = memory_get_usage(); $this->output("

Memory Before: " . number_format($memory_before / 1024, 3) . " KB
"); $this->output("Memory After: " . number_format($memory_after / 1024, 3) . " KB
"); $this->output("Memory Used: " . number_format(($memory_after - $memory_before) / 1024, 3) . " KB

"); } /* * 结束时把消息出栈,存入到_prevMessages中 */ $this->_prevMessages = array_pop($this->_content) . $this->_prevMessages . $this->_message . '
'; $this->_message = ''; /** * todo 这个判断有些问题,如果有两个系统需要benchmark,会出错 */ if (count($this->_content) == 1) { echo array_pop($this->_content) . $this->_prevMessages; } } } // End ^ Native EOL ^ encoding