gabrielef/timer

Tiny PHP timer utility to measure time

0.0.2 2021-07-24 17:04 UTC

This package is auto-updated.

Last update: 2024-04-24 23:28:11 UTC


README

Tiny PHP timer utility to measure time

Install

$ composer require gabrielef/timer

Usage

Start a new timer with name and precision:

use gabrielef\Timer;

$t = new Timer();
$t->start('firstTimer', 3);

Retrieve the amount of time passed of a specific timer:

use gabrielef\Timer;

$t = new Timer();
$t->start('firstTimer', 3);

//...
//after 1s

echo $t->look('firstTimer'); //ex. 1.234

Stop the timer (this will also delete the timer):

use gabrielef\Timer;
$t = new Timer();
$t->start('firstTimer');

//...
//after 3s

echo $t->end('firstTimer'); //ex. 3

List all the available timer key:

use gabrielef\Timer;

$t = new Timer();
$t->start('firstTimer');
$t->start('secondTimer');
$t->start('thirdTimer');

$list = $t->list(); // ['firstTimer', 'secondTimer', 'thirdTimer]

Test

Currently using PHPUnit with the following command:

$ docker run --rm -v $(pwd):/app -w /app php:7.3-cli ./vendor/bin/phpunit --debug