Skip to content

Commit a79a5b7

Browse files
committed
Update README.md
1 parent ac2ed8b commit a79a5b7

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

README.md

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# PHP Timer
22

3-
[![Latest Stable Version](https://poser.pugx.org/ayesh/php-timer/v/stable)](https://packagist.org/packages/ayesh/php-timer) [![License](https://poser.pugx.org/ayesh/php-timer/license)](https://packagist.org/packages/ayesh/php-timer) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Ayesh/php-timer/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Ayesh/php-timer/?branch=master) [![CI](https://github.com/Ayesh/php-timer/workflows/CI/badge.svg)](https://github.com/Ayesh/php-timer/actions) [![codecov](https://codecov.io/gh/Ayesh/php-timer/branch/master/graph/badge.svg)](https://codecov.io/gh/Ayesh/php-timer) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/54bcf54f-5087-45bf-9813-63c79a06a642/mini.png)](https://insight.sensiolabs.com/projects/54bcf54f-5087-45bf-9813-63c79a06a642) [![Too many badges](https://img.shields.io/badge/style-too_many-brightgreen.svg?style=toomany&label=badges)](https://github.com/Ayesh/php-timer)
3+
[![Latest Stable Version](https://poser.pugx.org/ayesh/php-timer/v/stable)](https://packagist.org/packages/ayesh/php-timer) [![License](https://poser.pugx.org/ayesh/php-timer/license)](https://packagist.org/packages/ayesh/php-timer) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Ayesh/php-timer/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Ayesh/php-timer/?branch=master) [![CI](https://github.com/Ayesh/php-timer/workflows/CI/badge.svg)](https://github.com/Ayesh/php-timer/actions) [![codecov](https://codecov.io/gh/Ayesh/php-timer/branch/master/graph/badge.svg)](https://codecov.io/gh/Ayesh/php-timer) [![Too many badges](https://img.shields.io/badge/style-too_many-brightgreen.svg?style=toomany&label=badges)](https://github.com/Ayesh/php-timer)
44

55
## Synopsis
66
A helper class to calculate how long a particular task took.
@@ -17,17 +17,18 @@ This class is similar to phpunit/php-timer, but not a fork, nor mimic its functi
1717

1818
## Prerequisites
1919

20-
- PHP 7.2 or later.
20+
- PHP 8.2 or later.
2121

2222
## Installing
23+
2324
The simplest way would be to install using [composer](https://getcomposer.org).
25+
2426
```bash
2527
composer require ayesh/php-timer
2628
```
2729

28-
If, for some reason you can't use Composer, or don't want to (oh come on!), you can integrate the class with your current `PSR-4` autoloader by mapping `Ayesh\PHP_TIMER` namespace to the repository's `src` folder.
29-
3030
## Usage
31+
3132
It is pretty simple to use the timer, with all methods being static, and allowing only 4 methods.
3233

3334
#### Start timer
@@ -51,43 +52,57 @@ Attempting to start the timer with a non-string key will throw a `\TypeError` ex
5152
You can call the `start` method multiple times even if the timer has started. It will not reset the timer.
5253

5354
#### Read timer
55+
5456
After starting the timer, you can read the elapsed time at any time. Reading the time will not stop the timer. You can read the timer, do some expensive calculations, and read again to get the cumulative time.
57+
5558
```php
5659
Timer::read(); // Default timer.
5760
Timer::read('default'); // Default timer.
5861
Timer::read('something'); // Timer started with key "something".
5962
```
63+
6064
Attempting to read a timer that is not started will throw an `\LogicException` exception.
6165

6266
##### Formats
67+
6368
You can pass a second argument to let this library make minimal processing for you:
69+
6470
```php
6571
Timer::read('something', Timer::FORMAT_PRECISE); // 0.10180473327637
6672
```
73+
6774
See the formats section below for the formats supported.
75+
6876
#### Stop timer
77+
6978
You can stop the timer anytime as well. This makes the library store the stop time, and your further `Timer::read()` calls will always return the time it took between start and stop.
79+
7080
```php
7181
Timer::stop(); // Default timer.
7282
Timer::stop('something'); // Timer started with key "something"
7383
```
84+
7485
Attempting to stop a timer that is not started will throw an `\LogicException` exception.
7586

7687
#### Reset timer
88+
7789
By default, starting the timer after stopping it will continue it from where it left off. For example, if you have 3 seconds on the timer when you stop it, and start it again, the total time will start from 3 seconds. You can explicitly reset the timer to make it start from 0.
7890
Resetting the timer will not make the timer start again. You need to explicitly start the timer again with a `Timer::start()` call.
91+
7992
```php
8093
Timer::reset(); // Default timer.
8194
Timer::reset('something');
8295
Timer::resetAll(); // Resets all timers.
8396
```
97+
8498
## Formats
99+
85100
Currently, the following formats are provided:
86101

87102
- `FORMAT_PRECISE`: Precise timer value, without rounding it. e.g. `0.10180473327637`
88103
- `FORMAT_MILLISECONDS`: Time in milliseconds, rounded to 2 decimals.
89104
- `FORMAT_SECONDS`: Time in seconds, rounded to 3 decimals.
90-
- `FORMAT_HUMAN`: Time in human readable format, for example `1.05 minutes`.
105+
- `FORMAT_HUMAN`: Time in human-readable format, for example `1.05 minutes`.
91106

92107
## Examples
93108

@@ -101,7 +116,9 @@ Currently, the following formats are provided:
101116
$time = Timer::read('default', Timer::FORMAT_SECONDS);
102117
echo "Script took {$time} second(s)";
103118
````
119+
104120
#### Stop watch functionality, with stop-and-go timer calculated separately.
121+
105122
```php
106123
<?php
107124
use Ayesh\PHP_Timer\Timer;
@@ -122,10 +139,12 @@ Currently, the following formats are provided:
122139
echo "<br />";
123140
echo Timer::read('laps', Timer::FORMAT_SECONDS); // 2 seconds (1 + 1)
124141
````
142+
125143
## Development and tests
144+
126145
All issues are PRs are welcome. Travis CI and PHPUnit tests are included. If you are adding new features, please make sure to add the test coverage.
127146

128147
## Credits
129-
By [Ayesh Karunaratne](https://ayesh.me) and [contributors](https://github.com/Ayesh/php-timer/graphs/contributors).
148+
By [Ayesh Karunaratne](https://aye.sh) and [contributors](https://github.com/Ayesh/php-timer/graphs/contributors).
130149

131150
kthxbye

0 commit comments

Comments
 (0)