musoftware / support
PragmaRX components support package
v0.9.3
2020-09-27 14:43 UTC
Requires
- php: >=5.4.0
- illuminate/filesystem: ~4.0|~5.0|~6.0|~7.0|~8.0
- symfony/var-dumper: ~2.6|~3.0|~4.0|~5.0
Suggests
- laravel/framework: Laravel framework.
- symfony/yaml: The Yaml class needs it
- v0.9.3
- 0.9.2
- v0.9.1
- v0.9.0
- v0.8.8
- v0.8.7
- v0.8.6
- v0.8.5
- v0.8.4
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- dev-master / 0.7.x-dev
- v0.7.4
- v0.7.3
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.16
- v0.6.15
- v0.6.14
- v0.6.13
- v0.6.12
- v0.6.11
- v0.6.10
- v0.6.9
- v0.6.8
- v0.6.7
- v0.6.6
- v0.6.5
- v0.6.4
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.3.5
- v0.3.4
- v0.3.3
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.9
- v0.2.8
- v0.2.7
- v0.2.6
- v0.2.5
- v0.2.4
- v0.2.3
- v0.2.1
- v0.2.0
This package is auto-updated.
Last update: 2024-11-10 09:55:38 UTC
README
Timer
A timer class that can be called static or dynamically.
Source code: support/blob/master/src/Timer.php
Methods
Those are the methods:
Timer::start();
Timer::stop();
Timer::isStarted();
Timer::isStopped();
Timer::elapsed(); // returns a formatted value 9.0192
Timer::elapsedRaw(); // returns a double 9.019223049023
Timer::setFormat(default = '%.4f');
You can name your timers and have more than one running:
Timer::start('mary');
Timer::stop('mary');
Timer::elapsed('mary');
Examples
Timer::start();
Timer::start('2nd timer');
var_dump("started: " . (Timer::isStarted() ? 'yes' : 'no'));
var_dump("stopped: " . (Timer::isStopped() ? 'yes' : 'no'));
sleep(5);
Timer::stop();
var_dump("started: " . (Timer::isStarted() ? 'yes' : 'no'));
var_dump("stopped: " . (Timer::isStopped() ? 'yes' : 'no'));
var_dump("elapsed: " . Timer::elapsed());
var_dump("raw: " . Timer::elapsedRaw());
sleep(2);
var_dump("'2nd timer' started: " . (Timer::isStarted('2nd timer') ? 'yes' : 'no'));
var_dump("'2nd timer' stopped: " . (Timer::isStopped('2nd timer') ? 'yes' : 'no'));
var_dump("'2nd timer' elapsed: " . Timer::elapsed('2nd timer'));
var_dump("'2nd timer' raw: " . Timer::elapsedRaw('2nd timer'));
sleep(2);
Timer::stop('2nd timer');
var_dump("'2nd timer' started: " . (Timer::isStarted('2nd timer') ? 'yes' : 'no'));
var_dump("'2nd timer' stopped: " . (Timer::isStopped('2nd timer') ? 'yes' : 'no'));
var_dump("'2nd timer' elapsed: " . Timer::elapsed('2nd timer'));
var_dump("'2nd timer' raw: " . Timer::elapsedRaw('2nd timer'));
Timer::setFormat('%.8f');
var_dump("'2nd timer' elapsed 8 decimals: " . Timer::elapsed('2nd timer'));
/// And you can instantiate it and do it all over again:
$t = new Timer;
$t->start();
sleep(3);
$t->stop();
var_dump("elapsed dynamic: " . $t->elapsed());
This should give you this result:
string(12) "started: yes"
string(11) "stopped: no"
string(11) "started: no"
string(12) "stopped: yes"
string(15) "elapsed: 5.0004"
string(20) "raw: 5.0005040168762"
string(24) "'2nd timer' started: yes"
string(23) "'2nd timer' stopped: no"
string(27) "'2nd timer' elapsed: 7.0008"
string(32) "'2nd timer' raw: 7.0008120536804"
string(23) "'2nd timer' started: no"
string(24) "'2nd timer' stopped: yes"
string(27) "'2nd timer' elapsed: 9.0011"
string(32) "'2nd timer' raw: 9.0010931491852"
string(42) "'2nd timer' elapsed 8 decimals: 9.00113106"
string(27) "elapsed dynamic: 3.00018883"