Debug::timer()

Measure time between two events

First call should be to $timer = Debug::timer(); with no arguments, or provide your own key/name as an argument.

Second call should pass the $timer given by the first call to get the time elapsed, i.e. $elapsed = Debug::timer($timer);.

Note that you may make multiple calls back to Debug::timer($timer) with the same key and it will continue returning the elapsed time since the original call. If you want to reset or remove the timer, call removeTimer or resetTimer.

Example

// typical usage
$timer = Debug::timer();
some_code_that_you_want_to_time();
$seconds = Debug::timer($timer);

// using a named timer
Debug::timer('foobar');
some_code_that_you_want_to_time();
$seconds = Debug::timer('foobar');

// optionally remove the timer
Debug::removeTimer('foobar');

Usage

// basic usage
$string = Debug::timer();

// usage with all arguments
$string = Debug::timer(string $key = '', bool $reset = false);

Arguments

NameType(s)Description
$key (optional)string

Leave blank to start timer. Specify existing key (string) to return timer. Specify new made up key to start a named timer.

$reset (optional)bool

If the timer already exists, it will be reset when this is true.

Return value

string int


Debug methods and properties

API reference based on ProcessWire core version 3.0.257