bonsaicode / timer
Timer utility class for benchmarking your PHP code.
1.0.6
2026-11-14 17:18 UTC
Requires
- php: >=7.1
Requires (Dev)
- phpunit/phpunit: ^9.6 || ^10.5 || ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Timer utility class.
- Timer class for benchmarking your code.
Requirements
- PHP 7.1 or higher
Installation
To install the package, run the following command in the console:
$ composer require "bonsaicode/timer"
Usage
<?php
# instantiating Timer automatically starts the timer unless you pass false to the constructor
$timer = new BonsaiCode\Timer();
# ... code you want to time here ...
# get the elapsed time as a string, defaults to 8 decimal places
echo 'Elapsed seconds: '.$timer->get()."\n";
# restart the timer
$timer->start();
# ... code you want to time here ...
# pause the timer
$timer->pause();
# ... code you want to time here ...
# resume the timer
$timer->unpause();
# show elapsed time since the last start, exclude all paused time
echo 'Elapsed seconds: '.$timer->get()."\n";
?>