/**
  * Start Timer test
  *
  * @return void
  **/
 function testTimers()
 {
     $this->assertTrue(DebugKitDebugger::startTimer('test1', 'this is my first test'));
     usleep(5000);
     $this->assertTrue(DebugKitDebugger::stopTimer('test1'));
     $elapsed = DebugKitDebugger::elapsedTime('test1');
     $this->assertTrue($elapsed > 0.005);
     $this->assertTrue(DebugKitDebugger::startTimer('test2', 'this is my second test'));
     sleep(1);
     $this->assertTrue(DebugKitDebugger::stopTimer('test2'));
     $elapsed = DebugKitDebugger::elapsedTime('test2');
     $this->assertTrue($elapsed > 1);
     DebugKitDebugger::startTimer('test3');
     $this->assertFalse(DebugKitDebugger::elapsedTime('test3'));
     $this->assertFalse(DebugKitDebugger::stopTimer('wrong'));
 }
/**
 * Start Timer test
 *
 * @return void
 **/
	public function testTimers() {
		$this->assertTrue(DebugKitDebugger::startTimer('test1', 'this is my first test'));
		usleep(5000);
		$this->assertTrue(DebugKitDebugger::stopTimer('test1'));
		$elapsed = DebugKitDebugger::elapsedTime('test1');
		$this->assertTrue($elapsed > 0.0050);

		$this->assertTrue(DebugKitDebugger::startTimer('test2', 'this is my second test'));
		sleep(1);
		$this->assertTrue(DebugKitDebugger::stopTimer('test2'));
		$elapsed = DebugKitDebugger::elapsedTime('test2');
		$expected = strpos(PHP_OS, 'WIN') === false ? 1 : 0.95; // Windows timer's precision is bad
		$this->assertTrue($elapsed > $expected);

		DebugKitDebugger::startTimer('test3');
		$this->assertIdentical(DebugKitDebugger::elapsedTime('test3'), 0);
		$this->assertFalse(DebugKitDebugger::stopTimer('wrong'));
	}
 /**
  * Get all timers that have been started and stopped.
  * Calculates elapsed time for each timer.
  *
  * @return array
  **/
 function getTimers()
 {
     $_this =& DebugKitDebugger::getInstance();
     $times = array();
     foreach ($_this->__benchmarks as $name => $timer) {
         $times[$name]['time'] = DebugKitDebugger::elapsedTime($name);
         $times[$name]['message'] = $timer['message'];
     }
     return $times;
 }
Esempio n. 4
0
 /**
  * Get all timers that have been started and stopped.
  * Calculates elapsed time for each timer. If clear is true, will delete existing timers
  *
  * @param bool $clear false
  * @return array
  * @access public
  **/
 function getTimers($clear = false)
 {
     $_this =& DebugKitDebugger::getInstance();
     $start = DebugKitDebugger::requestStartTime();
     $now = getMicrotime();
     $times = array();
     if (!empty($_this->__benchmarks)) {
         $firstTimer = current($_this->__benchmarks);
         $_end = $firstTimer['start'];
     } else {
         $_end = $now;
     }
     $times['Core Processing (Derived)'] = array('message' => __d('debug_kit', 'Core Processing (Derived)', true), 'start' => 0, 'end' => $_end - $start, 'time' => round($_end - $start, 6), 'named' => null);
     foreach ($_this->__benchmarks as $name => $timer) {
         if (!isset($timer['end'])) {
             $timer['end'] = $now;
         }
         $times[$name] = array_merge($timer, array('start' => $timer['start'] - $start, 'end' => $timer['end'] - $start, 'time' => DebugKitDebugger::elapsedTime($name)));
     }
     if ($clear) {
         $_this->__benchmarks = array();
     }
     return $times;
 }