https://github.com/amnuts/timer
This is a ridiculously simple microsecond timer for you to use within your PHP applications.
https://github.com/amnuts/timer
php simple timer
Last synced: over 1 year ago
JSON representation
This is a ridiculously simple microsecond timer for you to use within your PHP applications.
- Host: GitHub
- URL: https://github.com/amnuts/timer
- Owner: amnuts
- Created: 2020-09-19T17:45:38.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2023-07-28T17:44:08.000Z (almost 3 years ago)
- Last Synced: 2025-01-29T21:54:34.429Z (over 1 year ago)
- Topics: php, simple, timer
- Language: PHP
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple Timer
This is a ridiculously simple microsecond timer for you to use within your PHP applications.
It starts the timer when you instantiate the class and from there you can `mark` points of delta along the way and `stop` the timer.
Really; could it get simpler?
# Usage examples
```php
stop();
```
and that'll give us the result of:
```
Started 2020-09-19 16:06:52
Ended 2020-09-19 16:06:57, total time 0d 0h 0m 5.000200s
```
Simple, but kinda boring. However, if you have a function that you're wanting to time which has lots of parts, then it's useful to place markers throughout and see the difference between each part.
For example:
```php
mark();
sleep(2);
$timer->mark();
sleep(3);
$timer->stop();
echo $timer;
```
will give us the result of:
```
Started 2020-09-19 16:11:59
Δ 0d 0h 0m 1.000200s
Δ 0d 0h 0m 2.000700s
Ended 2020-09-19 16:12:05, total time 0d 0h 0m 6.001800s
```
The `mark` method allows us to see the delta between each time it's marked. But it can be even more helpful with supplying a message for the mark:
```php
mark('Starting something slow');
sleep(2);
$timer->mark('Ended that and going onto something even slower!');
sleep(3);
$timer->stop();
echo $timer;
```
and that gives us:
```
Started 2020-09-19 16:14:51
Δ 0d 0h 0m 1.000700s (Starting something slow)
Δ 0d 0h 0m 2.000700s (Ended that and going onto something even slower!)
Ended 2020-09-19 16:14:57, total time 0d 0h 0m 6.001900s
```
And, to be honest, you don't even need to `stop` the timer to output the current delta. You could just do this:
```