izabolotnev/php-timer

Utility class for timing

2.1 2016-03-24 12:54 UTC

This package is auto-updated.

Last update: 2024-05-05 17:49:15 UTC


README

Build Status

Timer

Utility class for timing things

Installation

To add this package as a local, per-project dependency to your project, simply add a dependency on izabolotnev/php-timer to your project's composer.json file. Here is a minimal example of a composer.json file that just defines a dependency on Timer:

{
    "require": {
        "izabolotnev/php-timer": "~2.1"
    }
}

Usage

Basic Timing

use izabolotnev\Timer;

Timer::start();

// ...

$time = Timer::stop();

print Timer::secondsToTimeString($time);

or

use izabolotnev\Timer;

Timer::start();

// ...

print Timer::stopAndFormat();

The code above yields the output below:

0 ms.

Advanced usage

use izabolotnev\Timer;

Timer::addNewTimer('myTimer');
Timer::start();

sleep(2);

Timer::start('myTimer');
echo 'Default: ', Timer::stopAndFormat(), PHP_EOL;

sleep(3);

echo 'Custom: ', Timer::stopAndFormat('myTimer'), PHP_EOL;

The code above yields the output below:

Default: 2 s.
Custom: 3 s.