Hazaar
Timer
Timer class for measuring how long things take

The timer class can be used to time one or more events and returns how long it took in milliseconds.

Application Timer

The Hazaar\Application class has a built-in timer for measuring the performance of your application automatically. By default this timer is disabled. See the app.timer setting in Config Directives.

Summary
MethodsPropertiesConstants
No constants
Properties
$last
$last
The name of the last timer. Used in checkpointing.
$precision
$precision
Timer Precision

This sets the precision of the output. By default it is 2 which means output is 1/10th of a millisecond.

$timers
$timers
Array of timers
Methods
__construct()
__construct($precision = 2)
Timer class constructor

The timer class has an implicit timer that is always active called the 'global' timer. This is simply used to record how long the timer class itself has been active.

__tostring()
__tostring() : string
Magic toString method

This will return a string representation of the current state of the default timer object.

all()
all($precision = null) : float[]
Get an array of all timers and their current state
checkpoint()
checkpoint($name) : boolean
Create a timer checkpoint.

Simply put, this will automatically stop the last timer and start a new one in one function call.

get()
get($name = 'default', $precision = null) : float
Get the current state of a timer.

If a timer is currently running, then it's value will be the difference between when it started and 'now'. If a timer has stopped, it's value will be the difference between when it was started and when it stopped.

start()
start($name = 'default', $when = null)
Start a new timer.

A timer is nothing more than a named point in time. When a timer starts, no long running code is executed or anything like that and simply the current system time in microseconds is recorded against the timer name. This allows us to later query that timer name and return the difference which will give you the number of milliseconds between two points in time.

stop()
stop($name = 'default') : float
Stop a currently running timer and return it's value