README completion and more readable test

master 1.0.0
Julien Rosset 4 years ago
parent d12f197345
commit 2763cbdb87

@ -13,48 +13,53 @@ Include step time measurement.
composer require darkelfe14728/executiontimer composer require darkelfe14728/executiontimer
``` ```
[comment]: <> (## Description) ## Description
[comment]: <> (At first, create a new CommandLine with program name and description. Add options and values by using respectively _addOption_ and _addValue_.) When you create the ExecutionTimer, il will start automatically, except if you pass “false”.
[comment]: <> (Default options for help &#40;-h / --help&#41; and version &#40;--version&#41; can be add with _addDefaultArguments_ and use _treatDefaultArguments_ for launching associated treatments.) 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.
[comment]: <> (Treat script arguments with _parse_ : return an object of variables.) 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).
[comment]: <> (## Example ) ## Example
```php
<?php
[comment]: <> (```php) use jrosset\ExecutionTimer\ExecutionTimer;
[comment]: <> (<?php) $timer = new ExecutionTimer(false);
$timer->start();
[comment]: <> (use CommandLine\CommandLine;) sleep(3);
[comment]: <> (use CommandLine\Argument\Option\Flag;) $timer->step('sleep 1');
echo $timer->getLastStepRelativeDuration()->toUserString() . PHP_EOL;
echo $timer->getLastStepDuration() . PHP_EOL;
[comment]: <> (use CommandLine\Argument\Parser\StringParser;) sleep(2);
[comment]: <> (use CommandLine\Argument\Value\Value;) $timer->step('sleep 2');
echo $timer->getLastStepRelativeDuration()->toUserString() . PHP_EOL;
echo $timer->getLastStepDuration() . PHP_EOL;
$timer->stop();
[comment]: <> ($cmdline = new CommandLine&#40;'Checker', 'File checker', 'php checker.php'&#41;;) $final = $timer->getDuration();
echo $timer->getRelativeDuration()->toUserString() . PHP_EOL;
echo $timer->getRelativeDuration() . PHP_EOL;
[comment]: <> ($cmdline->addDefaultArguments&#40;&#41;;) echo $timer->getDuration()->toUserString() . PHP_EOL;
echo $timer->getDuration() . PHP_EOL;
[comment]: <> ($cmdline->addOption&#40;new Flag&#40;'enhanced', false, 'Deep check ?'&#41;&#41;;) ```
[comment]: <> ($cmdline->addValue&#40;new Value&#40;'path', 'File path', new StringParser&#40;&#41;&#41;&#41;;)
[comment]: <> (var_dump&#40;$args = $cmdline->parse&#40;&#41;&#41;;)
[comment]: <> ($cmdline->treatDefaultArguments&#40;$args&#41;;)
[comment]: <> (```)
[comment]: <> (Would display something like that : )
[comment]: <> ( class stdClass#13 &#40;1&#41; {)
[comment]: <> ( public $enhanced => bool&#40;false&#41;)
[comment]: <> ( public $path => string&#40;"my/path/to/a/file"&#41;) Would display something like that :
[comment]: <> ( }) 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

@ -10,16 +10,19 @@ $timer->start();
sleep(3); sleep(3);
$timer->step('sleep 1'); $timer->step('sleep 1');
var_dump($timer->getLastStepRelativeDuration()->toUserString(), (string)$timer->getLastStepDuration()); echo $timer->getLastStepRelativeDuration()->toUserString() . PHP_EOL;
echo $timer->getLastStepDuration() . PHP_EOL;
sleep(2); sleep(2);
$timer->step('sleep 2'); $timer->step('sleep 2');
var_dump($timer->getLastStepRelativeDuration()->toUserString(), (string)$timer->getLastStepDuration()); echo $timer->getLastStepRelativeDuration()->toUserString() . PHP_EOL;
echo $timer->getLastStepDuration() . PHP_EOL;
$timer->stop(); $timer->stop();
var_dump($timer->getStepsDuration());
$final = $timer->getDuration(); $final = $timer->getDuration();
var_dump($timer->getRelativeDuration()->toUserString(), (string)$final); echo $timer->getRelativeDuration()->toUserString() . PHP_EOL;
var_dump($final->getMilliseconds(), $final->getMilliseconds()->asAbsoluteFactional(), $final->getMilliseconds()->asRelativeFactional()); echo $timer->getRelativeDuration() . PHP_EOL;
echo $timer->getDuration()->toUserString() . PHP_EOL;
echo $timer->getDuration() . PHP_EOL;
Loading…
Cancel
Save