You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
phpexecutiontimer/README.md

66 lines
1.9 KiB
Markdown

# PHPExecutionTimer
__Utility class for execution time measurement__
![last release](https://badgen.net/packagist/v/darkelfe14728/executiontimer?label=Last%20release)
![licence](https://badgen.net/packagist/license/darkelfe14728/executiontimer?color=red)
![nb releases](https://badgen.net/packagist/dt/darkelfe14728/executiontimer?color=green)
A utility class to measure and display execution time.
Include step time measurement.
## Installation
```
composer require darkelfe14728/executiontimer
```
## Description
When you create the ExecutionTimer, il will start automatically, except if you pass “false”.
Call start(), step() and stop() to respectively start, store a step and stop the time measurement.
Then you could use getDuration() or getRelativeDuration() to get durations.
Each duration can export to multiple units (microseconds, millseconds, seconds, minutes, hours and days).
With these units, you can get the full value (12.5 secondes = 12500 milliseconds) or relative to upper units (12.5 seconds => 500 milliseconds).
## Example
```php
<?php
use jrosset\ExecutionTimer\ExecutionTimer;
$timer = new ExecutionTimer(false);
$timer->start();
sleep(3);
$timer->step('sleep 1');
echo $timer->getLastStepRelativeDuration()->toUserString() . PHP_EOL;
echo $timer->getLastStepDuration() . PHP_EOL;
sleep(2);
$timer->step('sleep 2');
echo $timer->getLastStepRelativeDuration()->toUserString() . PHP_EOL;
echo $timer->getLastStepDuration() . PHP_EOL;
$timer->stop();
$final = $timer->getDuration();
echo $timer->getRelativeDuration()->toUserString() . PHP_EOL;
echo $timer->getRelativeDuration() . PHP_EOL;
echo $timer->getDuration()->toUserString() . PHP_EOL;
echo $timer->getDuration() . PHP_EOL;
```
Would display something like that :
3 seconds and 8 milliseconds
0 0:0:3.8966
2 seconds and 6 milliseconds
0 0:0:5.15912
0 0:0:0.0442
5 seconds and 16 milliseconds
0 0:0:5.16354