W3cubDocs

/Drupal 8

static public function Timer::stop

static public Timer::stop($name)

Stops the timer with the specified name.

Parameters

string $name: The name of the timer.

Return value

array A timer array. The array contains the number of times the timer has been started and stopped (count) and the accumulated timer value in ms (time).

File

core/lib/Drupal/Component/Utility/Timer.php, line 60

Class

Timer
Provides helpers to use timers throughout a request.

Namespace

Drupal\Component\Utility

Code

static public function stop($name) {
  if (isset(static::$timers[$name]['start'])) {
    $stop = microtime(TRUE);
    $diff = round(($stop - static::$timers[$name]['start']) * 1000, 2);
    if (isset(static::$timers[$name]['time'])) {
      static::$timers[$name]['time'] += $diff;
    }
    else {
      static::$timers[$name]['time'] = $diff;
    }
    unset(static::$timers[$name]['start']);
  }

  return static::$timers[$name];
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Component!Utility!Timer.php/function/Timer::stop/8.1.x