elapsedTime() public static method

Get the difference in time between the timer start and timer end.
public static elapsedTime ( string $name = 'default', integer $precision = 5 ) : float
$name string the name of the timer you want elapsed time for.
$precision integer the number of decimal places to return, defaults to 5.
return float number of seconds elapsed for timer name, 0 on missing key
Ejemplo n.º 1
0
 /**
  * Helper method for doing non-GET requests.
  *
  * @param string $method  HTTP method.
  * @param string $url     URL to request.
  * @param mixed  $data    The request body.
  * @param array  $options The options to use. Contains auth, proxy etc.
  *
  * @return \Cake\Network\Http\Response
  */
 protected function _doRequest($method, $url, $data, $options)
 {
     $request = $this->_createRequest($method, $url, $data, $options);
     $timerKey = 'debug_http.call.' . $url;
     if (Configure::read('debug')) {
         DebugTimer::start($timerKey, $method . ' ' . $url);
     }
     $response = $this->send($request, $options);
     if (Configure::read('debug')) {
         DebugTimer::stop($timerKey);
         ClientCallPanel::addCall($request, $response, DebugTimer::elapsedTime($timerKey));
     }
     return $response;
 }
Ejemplo n.º 2
0
 /**
  * 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 = stripos(PHP_OS, 'win') === false ? 0.999 : 0.95;
     // Windows timer's precision is bad
     $this->assertTrue($elapsed >= $expected);
     DebugTimer::start('test3');
     $this->assertSame(DebugTimer::elapsedTime('test3'), 0);
     $this->assertFalse(DebugTimer::stop('wrong'));
 }
Ejemplo n.º 3
0
 /**
  * @param $identifier
  * @param array $parameters
  * @param null $context
  * @throws MacroException
  * @return mixed
  */
 public function runMacro($identifier, array $parameters = [], $context = null, array $options = [])
 {
     $options = Hash::merge(['validate' => false], $options);
     if (Plugin::loaded('DebugKit')) {
         DebugTimer::start(__d('macro', 'Macro: {0}', $identifier));
     }
     $macroParts = explode('::', $identifier);
     $name = $macroParts[0];
     $method = isset($macroParts[1]) ? $macroParts[1] : 'run';
     $this->getMacroRegistry()->reset();
     $config = [];
     /** @var Macro $macro */
     try {
         $macro = $this->getMacroRegistry()->load($name, $config);
         if ($context) {
             $macro->context($context);
         }
     } catch (MacroException $missing) {
         if (!$options['validate']) {
             throw $missing;
         }
         return $missing;
     }
     $callable = [$macro, $method];
     if (!is_callable($callable)) {
         $exception = new MissingMacroMethodException('Unknown method \'' . $method . '\' in macro ' . get_class($macro));
         if (!$options['validate']) {
             throw $exception;
         }
         return $exception;
     }
     $result = call_user_func_array($callable, $parameters);
     $elapsedTime = null;
     if (Plugin::loaded('DebugKit')) {
         $elapsedTime = DebugTimer::elapsedTime(__d('macro', 'Macro: {0}', $identifier), 10) * 1000;
         DebugTimer::stop(__d('macro', 'Macro: {0}', $identifier));
     }
     DebugMacro::record($identifier, $parameters, $context, $options, $result, $elapsedTime);
     if ($options['validate']) {
         return true;
     }
     return $result;
 }