diff --git a/README.md b/README.md index eb99340..db986a1 100644 --- a/README.md +++ b/README.md @@ -13,48 +13,53 @@ Include step time measurement. 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 (-h / --help) and version (--version) 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) +use jrosset\ExecutionTimer\ExecutionTimer; -[comment]: <> (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('Checker', 'File checker', 'php checker.php');) +$final = $timer->getDuration(); +echo $timer->getRelativeDuration()->toUserString() . PHP_EOL; +echo $timer->getRelativeDuration() . PHP_EOL; -[comment]: <> ($cmdline->addDefaultArguments();) - -[comment]: <> ($cmdline->addOption(new Flag('enhanced', false, 'Deep check ?'));) - -[comment]: <> ($cmdline->addValue(new Value('path', 'File path', new StringParser()));) - -[comment]: <> (var_dump($args = $cmdline->parse());) - -[comment]: <> ($cmdline->treatDefaultArguments($args);) - -[comment]: <> (```) - -[comment]: <> (Would display something like that : ) - -[comment]: <> ( class stdClass#13 (1) {) - -[comment]: <> ( public $enhanced => bool(false)) +echo $timer->getDuration()->toUserString() . PHP_EOL; +echo $timer->getDuration() . PHP_EOL; +``` -[comment]: <> ( public $path => string("my/path/to/a/file")) +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 diff --git a/Tests/test.php b/Tests/test.php index c21a96e..705887e 100644 --- a/Tests/test.php +++ b/Tests/test.php @@ -10,16 +10,19 @@ $timer->start(); sleep(3); $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); $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(); -var_dump($timer->getStepsDuration()); - $final = $timer->getDuration(); -var_dump($timer->getRelativeDuration()->toUserString(), (string)$final); -var_dump($final->getMilliseconds(), $final->getMilliseconds()->asAbsoluteFactional(), $final->getMilliseconds()->asRelativeFactional()); \ No newline at end of file +echo $timer->getRelativeDuration()->toUserString() . PHP_EOL; +echo $timer->getRelativeDuration() . PHP_EOL; + +echo $timer->getDuration()->toUserString() . PHP_EOL; +echo $timer->getDuration() . PHP_EOL; \ No newline at end of file