Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

anglesoft/chrono

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⏱ Chrono

The easiest way to measure PHP code execution time.

Introduction

Every time I need to benchmark something, I find myself re-inventing the wheel and do manual time calculations. This hurts my productivity. I wanted a simple little package that is very easy to use that I can go to whenever I need to measure execution time in PHP.

  • Easy to remember (you need only to call 2 static methods to get what you want).
  • 100% tested (have a look at the test suite)
  • It has no dependencies (can work with any framework)

Installation

composer require angle/chrono

Usage

Basic usage:

use Angle\Chrono;

Chrono::start();

// Do something...

echo Chrono::stop(); // 2.42424242 (seconds)

To get formatted output, use the 'meter' method:

Chrono::start();

echo Chrono::meter(); // Time: 0.42 seconds (4242 ms)

You can access elapsed time whenever you need, in various formats:

echo Chrono::elapsed(); // 0.42424242
echo Chrono::seconds(); // 0.43
echo Chrono::ms(); // 4243

You can pause and resume the chronometer:

Chrono::start();

sleep(1);

Chrono::pause();

sleep(3); // Will be ignored

Chrono::resume();

sleep(1);

print Chrono::meter(); // Time: 2 seconds (2001 ms)

For a more detailed overview, please have a look at the test suite.

Credits

This implementation is inspired by David Walsh's timer class.

Contributing

Improvements are welcome! Feel free to submit pull requests.

Licence

MIT

Copyright © 2019 Angle Software

About

⏱ The easiest way to measure PHP code execution time.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.