Measure the passing of time -- by, Chris Kankiewicz (@phlak.dev), logo by Caneco
Chronometer is a library for statically measuring the passing of time in your code. It's intended to be used for benchmarking code execution time.
composer require phlak/Chronometer
First, import Chronometer.
use PHLAKChronometerTimer;
Then start your timer, run your code, stop the timer and get the elapsed time.
Timer::start();
// do something you want to measure...
Timer::stop();
return Timer::elapsed();
After running your timer you will need to reset it before using it again.
Timer::reset();
You may optionally reset the timer when you start it with the $reset
parameter.
Timer::start(reset: true);
Start the timer.
ChronometerTimer::start( [ $reset = false ] ) : float
ChronometerTimer::start(); // Returns something like 1538016612.1692
Stop the timer.
ChronometerTimer::stop( void ) : float
ChronometerTimer::stop(); // Returns something like 1538016632.7721
Add a new lap.
ChronometerTimer::addLap( [ string $description = null ] ) : ChronometerLap
$lap = ChronometerTimer::addLap('The first lap.');
$lap->time // Returns something like 1538016625.492
$lap->duration // Returns something like 7.999922990799
$lap->description // Returns 'The first lap.'
Return the timer start time.
ChronometerTimer::started( void ) : float
ChronometerTimer::started(); // Returns something like 1538016612.1692
Return the timer stop time.
ChronometerTimer::stopped( void ) : float
ChronometerTimer::stopped(); // Returns something like 1538016632.7721
Return the total time elapsed in seconds.
ChronometerTimer::elapsed( void ) : float
ChronometerTimer::elapsed(); // Returns something like 20.602929115295
Return the last lap.
ChronometerTimer::lastLap( void ) : ChronometerLap
$lap = ChronometerTimer::lastLap();
$lap->time // Returns something like 1538016632.7721
$lap->duration // Returns something like 7.2800490856171
Return an array of all laps.
ChronometerTimer::laps( void ) : array
ChronometerTimer::laps(); // Returns an array of Lap objects
Reset the timer state.
ChronometerTimer::reset( void ) : void
ChronometerTimer::reset();
A list of changes can be found on the GitHub Releases page.
For general help and support join our GitHub Discussion or reach out on Bluesky.
Please report bugs to the GitHub Issue Tracker.
This project is licensed under the MIT License.