You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+30-30Lines changed: 30 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -3,12 +3,12 @@
3
3
[](https://packagist.org/packages/ayesh/php-timer)[](https://packagist.org/packages/ayesh/php-timer)[](https://scrutinizer-ci.com/g/Ayesh/php-timer/?branch=v2)[](https://travis-ci.org/Ayesh/php-timer)[](https://codecov.io/gh/Ayesh/php-timer)[](https://insight.sensiolabs.com/projects/54bcf54f-5087-45bf-9813-63c79a06a642)[](https://github.com/Ayesh/php-timer)
4
4
5
5
## Synopsis
6
-
A helper class to calculate how long a particular task took.
6
+
A helper class to calculate how long a particular task took.
7
7
8
-
This class is similar to phpunit/php-timer, but not a fork, nor mimic its functionality.
8
+
This class is similar to phpunit/php-timer, but not a fork, nor mimic its functionality.
9
9
10
-
- Multiple timers by a given key.
11
-
- Read the current time elapsed without stopping the timer.
10
+
- Multiple timers by a given key.
11
+
- Read the current time elapsed without stopping the timer.
12
12
- Stop the timer, and continue from where it left (stopwatch).
13
13
- Dead simple API with only 4 static methods.
14
14
- 100% unit test coverage.
@@ -18,46 +18,46 @@ This class is similar to phpunit/php-timer, but not a fork, nor mimic its functi
18
18
## Prerequisites
19
19
20
20
- PHP 7.2 or later.
21
-
21
+
22
22
## Installing
23
-
The simplest way would be to install using [composer](https://getcomposer.org).
23
+
The simplest way would be to install using [composer](https://getcomposer.org).
24
24
```bash
25
25
composer require ayesh/php-timer
26
26
```
27
-
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.
27
+
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
29
30
30
## Usage
31
-
It is pretty simple to use the timer, with all methods being static, and allowing only 4 methods.
31
+
It is pretty simple to use the timer, with all methods being static, and allowing only 4 methods.
32
32
33
33
#### Start timer
34
34
```php
35
35
<?php
36
36
use Ayesh\PHP_Timer\Timer;
37
37
Timer::start();
38
38
````
39
-
This starts the timer (actually keeps the current time stored) with the key `default`. Throughout the library, if you do not provide a specific key, this default key is used.
39
+
This starts the timer (actually keeps the current time stored) with the key `default`. Throughout the library, if you do not provide a specific key, this default key is used.
40
40
41
41
Alternately, you can start the timer with a given key:
42
42
```php
43
43
Timer::start('something');
44
44
```
45
-
Once you start the time with a given key, you can use the same key to refer to that particular timer.
45
+
Once you start the time with a given key, you can use the same key to refer to that particular timer.
46
46
You can of course use PHP magic constants to make things easier:
47
47
```php
48
48
Timer::start(__FUNCTION__);
49
49
```
50
-
Attempting to start the timer with a non-string key will throw a `\TypeError` exception.
50
+
Attempting to start the timer with a non-string key will throw a `\TypeError` exception.
51
51
You can call the `start` method multiple times even if the timer has started. It will not reset the timer.
52
52
53
53
#### Read timer
54
-
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.
54
+
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.
55
55
```php
56
-
Timer::read(); // Default timer.
57
-
Timer::read('default'); // Default timer.
56
+
Timer::read(); // Default timer.
57
+
Timer::read('default'); // Default timer.
58
58
Timer::read('something'); // Timer started with key "something".
59
59
```
60
-
Attempting to read a timer that is not started will throw an `\LogicException` exception.
60
+
Attempting to read a timer that is not started will throw an `\LogicException` exception.
61
61
62
62
##### Formats
63
63
You can pass a second argument to let this library make minimal processing for you:
@@ -66,35 +66,35 @@ You can pass a second argument to let this library make minimal processing for y
66
66
```
67
67
See the formats section below for the formats supported.
68
68
#### Stop timer
69
-
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.
69
+
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.
70
70
```php
71
-
Timer::stop(); // Default timer.
71
+
Timer::stop(); // Default timer.
72
72
Timer::stop('something'); // Timer started with key "something"
73
73
```
74
-
Attempting to stop a timer that is not started will throw an `\LogicException` exception.
74
+
Attempting to stop a timer that is not started will throw an `\LogicException` exception.
75
75
76
76
#### Reset timer
77
-
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.
78
-
Resetting the timer will not make the timer start again. You need to explicitly start the timer again with a `Timer::start()` call.
77
+
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.
78
+
Resetting the timer will not make the timer start again. You need to explicitly start the timer again with a `Timer::start()` call.
79
79
```php
80
-
Timer::reset(); // Default timer.
81
-
Timer::reset('something');
80
+
Timer::reset(); // Default timer.
81
+
Timer::reset('something');
82
82
Timer::resetAll(); // Resets all timers.
83
83
```
84
84
## Formats
85
85
Currently, the following formats are provided:
86
86
87
87
-`FORMAT_PRECISE`: Precise timer value, without rounding it. e.g. `0.10180473327637`
88
88
-`FORMAT_MILLISECONDS`: Time in milliseconds, rounded to 2 decimals.
89
-
-`FORMAT_SECONDS`: Time in seconds, rounded to 3 decimals.
89
+
-`FORMAT_SECONDS`: Time in seconds, rounded to 3 decimals.
0 commit comments