/** * Start Timer test * * @return void */ public function testTimers() { $this->assertTrue(DebugTimer::start('test1', 'this is my first test')); usleep(5000); $this->assertTrue(DebugTimer::stop('test1')); $elapsed = DebugTimer::elapsedTime('test1'); $this->assertTrue($elapsed > 0.005); $this->assertTrue(DebugTimer::start('test2', 'this is my second test')); sleep(1); $this->assertTrue(DebugTimer::stop('test2')); $elapsed = DebugTimer::elapsedTime('test2'); $expected = strpos(PHP_OS, 'WIN') === false ? 0.999 : 0.95; // Windows timer's precision is bad $this->assertTrue($elapsed >= $expected); DebugTimer::start('test3'); $this->assertIdentical(DebugTimer::elapsedTime('test3'), 0); $this->assertFalse(DebugTimer::stop('wrong')); }
/** * Get the difference in time between the timer start and timer end. * * @param $name string the name of the timer you want elapsed time for. * @param $precision int the number of decimal places to return, defaults to 5. * @return float number of seconds elapsed for timer name, 0 on missing key * @deprecated use DebugTimer::elapsedTime() */ public static function elapsedTime($name = 'default', $precision = 5) { return DebugTimer::elapsedTime($name, $precision); }