Skip to content
Measure the passing of time.
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitattributes
.gitignore
.php_cs.dist
.styleci.yml
.travis.yml
LICENSE
README.md
composer.json
phpunit.xml

README.md

Chronometer

Latest Stable Version Total Downloads Author License Build Status StyleCI

Measure the passing of time -- by, Chris Kankiewicz (@PHLAK)

Introduction

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.

Like this project?

Join the community on Spectrum Become a Patron One-time Donation

Requirements

Install with Composer

composer require phlak/chronometer

Using Chronometer

First, import Chronometer.

use PHLAK\Chronometer\Timer;

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);

Usage

start

Start the timer.

Chronometer\Timer::start( [ $reset = false ] ) : float

Example

Chronometer\Timer::start(); // Returns something like 1538016612.1692

stop

Stop the timer.

Chronometer\Timer::stop( void ) : float

Example

Chronometer\Timer::stop(); // Returns something like 1538016632.7721

addLap

Add a new lap.

Chronometer\Timer::addLap( [ string $description = null ] ) : Chronometer\Lap

Example

$lap = Chronometer\Timer::addLap('The first lap.');

$lap->time // Returns something like 1538016625.492
$lap->duration // Returns something like 7.999922990799
$lap->description // Returns 'The first lap.'

started

Return the timer start time.

Chronometer\Timer::started( void ) : float

Example

Chronometer\Timer::started(); // Returns something like 1538016612.1692

stopped

Return the timer stop time.

Chronometer\Timer::stopped( void ) : float

Example

Chronometer\Timer::stopped(); // Returns something like 1538016632.7721

elapsed

Return the total time elapsed in seconds.

Chronometer\Timer::elapsed( void ) : float

Example

Chronometer\Timer::elapsed(); // Returns something like 20.602929115295

lastLap

Return the last lap.

Chronometer\Timer::lastLap( void ) : Chronometer\Lap

Example

$lap = Chronometer\Timer::lastLap();

$lap->time // Returns something like 1538016632.7721
$lap->duration // Returns something like 7.2800490856171

laps

Return an array of all laps.

Chronometer\Timer::laps( void ) : array

Example

Chronometer\Timer::laps(); // Returns an array of Lap objects

reset

Reset the timer state.

Chronometer\Timer::reset( void ) : void

Example

Chronometer\Timer::reset();

Changelog

A list of changes can be found on the GitHub Releases page.

Troubleshooting

For general help and support join our Spectrum community.

Please report bugs to the GitHub Issue Tracker.

Copyright

This project is licensed under the MIT License.

You can’t perform that action at this time.