Code Monkey home page Code Monkey logo

chronometer's Introduction

Chronometer

Join our Community Become a Sponsor One-time Donation
GitHub branch checks state

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

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.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.