izabolotnev / php-timer
Utility class for timing
Installs: 1 860
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 66
Open Issues: 0
Requires
- php: >=5.4
Requires (Dev)
- phpunit/phpunit: 5.0.*
README
Timer
Utility class for timing things
Installation
To add this package as a local, per-project dependency to your project, simply add a dependency on izabolotnev/php-timer
to your project's composer.json
file. Here is a minimal example of a composer.json
file that just defines a dependency on Timer:
{
"require": {
"izabolotnev/php-timer": "~2.1"
}
}
Usage
Basic Timing
use izabolotnev\Timer; Timer::start(); // ... $time = Timer::stop(); print Timer::secondsToTimeString($time);
or
use izabolotnev\Timer; Timer::start(); // ... print Timer::stopAndFormat();
The code above yields the output below:
0 ms.
Advanced usage
use izabolotnev\Timer; Timer::addNewTimer('myTimer'); Timer::start(); sleep(2); Timer::start('myTimer'); echo 'Default: ', Timer::stopAndFormat(), PHP_EOL; sleep(3); echo 'Custom: ', Timer::stopAndFormat('myTimer'), PHP_EOL;
The code above yields the output below:
Default: 2 s.
Custom: 3 s.