A collection of simple chronometers.
composer require pyrsmk/illuminator
Here's the base chrono.
$chrono = new Illuminator\Chrono();
// Start!
$chrono->start();
// Stop the chrono for some time...
$chrono->stop();
// Resume the chrono
$chrono->start();
// Return the time in seconds
$chrono->read();
// Reset the still running chrono
$chrono->reset();
// Return the reseted time
$chrono->read();
// Completely stop and reset the chrono
$chrono->stop();
$chrono->reset();
The time is returned as a microtime float number, in seconds. You can also read it in milliseconds with:
$chrono->readAsMilliseconds();
A lazy chrono that you don't need to start or whatever.
$chrono = new Illuminator\LazyChrono();
usleep(1000);
$chrono->read();
With that class, you can time a specific task.
$timedTask = new TimedTask(function () {
usleep(1000);
});
$timedTask->read();
Note that the callback will be run each time read()
is called.
Released under the MIT license.