Usage:

 use \MD\Foundation\Debug\Timer;
 $timer = new Timer();
 echo $timer->stop();
 // -> 41.54232349

 echo $timer->getMemoryUsage();
 // -> 34567123

Methods This class defines the following methods:

__construct (bool $instantStart = true)

Constructor.

Starts the timer automatically by default.

Arguments:
bool $instantStart

[optional] Should the timer be started immediately? Default: true.

start ()

Start the timer.

Throws:
BadMethodCallException

When the timer was already started.

stop (int $precision = 8) -> float

Stop the timer and return the result duration in seconds.

Example:

 $timer = new \MD\Foundation\Debug\Timer();
 echo $timer->stop(3);
 // -> 108.667
Arguments:
int $precision

[optional] How many places to round to. Default: 8

Returns:
float
Throws:
BadMethodCallException

When the timer was already stopped.

step (string $name = null) -> MD\Foundation\Debug\TimerStep

Stops the current step, starts a new one and returns the stopped one.

Arguments:
string $name

[optional] Name of the step that should be returned.

Returns:
MD\Foundation\Debug\TimerStep

getDuration (int $precision = 8) -> float

Returns the duration of the timer.

If not stopped yet then it will simply return time difference between its' start and current time.

Arguments:
int $precision

[optional] How many places to round to. Default: 8.

Returns:
float

getMemoryUsage () -> int

Returns the memory usage during the timer - the difference between the start memory and peak memory during the timer.

If not stopped yet then it will simply return memory difference between its' start and current memory usage.

Returns:
int

getStartTime () -> float

Returns seconds with microtime when the timer started.

Returns:
float

getStartMemory () -> int

Returns how many bytes of memory PHP was using when the timer started.

Returns:
int

getStartMemoryPeak () -> int

Returns how many bytes of memory PHP was using at most (peak) when the timer started.

Returns:
int

getCurrentStep () -> MD\Foundation\Debug\TimerStep

Returns the current active step.

Returns:
MD\Foundation\Debug\TimerStep

getStopTime () -> float

Returns seconds with microtime when the timer stopped.

Returns:
float

getStopMemory () -> int

Returns how many bytes of memory PHP was using when the timer stopped.

Returns:
int

getStopMemoryPeak () -> int

Returns how many bytes of memory PHP was using at most (peak) when the timer stopped.

Returns:
int

getSteps () -> array

Returns the steps.

Returns:
array

static difference (float $startTime, float $endTime, int $precision = 8) -> float

Calculates the difference between two times.

Arguments:
float $startTime

Start time.

float $endTime

End time.

int $precision

[optional] How many places to round to. Default: 8

Returns:
float

static memoryDifference (int $startMemory, int $endMemory) -> int

Calculates the difference between two memory usages.

Arguments:
int $startMemory

Start memory usage.

int $endMemory

End memory usage.

Returns:
int

static getMicroTime () -> float

Creates an easier to use value of PHP's microtime()

Returns:
float

static getCurrentMemory () -> int

Returns the current memory usage.

Returns:
int

static getCurrentMemoryPeak () -> int

Returns the current peak memory usage.

Returns:
int