CodeIgniter v4.5 API

Timer
in package

Class Timer

Provides a simple way to measure the amount of time that elapses between two points.

Tags
see
TimerTest

Table of Contents

Properties

$timers  : array<string|int, mixed>
List of all timers.

Methods

getElapsedTime()  : float|null
Returns the duration of a recorded timer.
getTimers()  : array<string|int, mixed>
Returns the array of timers, with the duration pre-calculated for you.
has()  : bool
Checks whether or not a timer with the specified name exists.
record()  : mixed
Executes callable and measures its time.
start()  : Timer
Starts a timer running.
stop()  : Timer
Stops a running timer.

Properties

$timers

List of all timers.

protected array<string|int, mixed> $timers = []

Methods

getElapsedTime()

Returns the duration of a recorded timer.

public getElapsedTime(string $name[, int $decimals = 4 ]) : float|null
Parameters
$name : string

The name of the timer.

$decimals : int = 4

Number of decimal places.

Return values
float|null

Returns null if timer does not exist by that name. Returns a float representing the number of seconds elapsed while that timer was running.

getTimers()

Returns the array of timers, with the duration pre-calculated for you.

public getTimers([int $decimals = 4 ]) : array<string|int, mixed>
Parameters
$decimals : int = 4

Number of decimal places

Return values
array<string|int, mixed>

has()

Checks whether or not a timer with the specified name exists.

public has(string $name) : bool
Parameters
$name : string
Return values
bool

record()

Executes callable and measures its time.

public record(string $name, callable(): mixed $callable) : mixed

Returns its return value if any.

Parameters
$name : string

The name of the timer

$callable : callable(): mixed

callable to be executed

start()

Starts a timer running.

public start(string $name[, float|null $time = null ]) : Timer

Multiple calls can be made to this method so that several execution points can be measured.

Parameters
$name : string

The name of this timer.

$time : float|null = null

Allows user to provide time.

Return values
Timer

stop()

Stops a running timer.

public stop(string $name) : Timer

If the timer is not stopped before the timers() method is called, it will be automatically stopped at that point.

Parameters
$name : string

The name of this timer.

Return values
Timer

        
On this page

Search results