sandermuller / stopwatch
Stopwatch to measure execution times (profile code) for Laravel and PHP projects
Installs: 11 780
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- illuminate/collections: ^11.0|^12.0
- illuminate/support: ^11.0|^12.0
- nesbot/carbon: ^2|^3
- symfony/var-dumper: ^7
Requires (Dev)
- laravel/pint: ^1.19
- nunomaduro/collision: ^8.5
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- rector/rector: ^2.0
- rector/type-perfect: ^2.0
- roave/security-advisories: dev-latest
- spaze/phpstan-disallowed-calls: ^4.0
- symplify/phpstan-extensions: ^12.0.1
- tomasvotruba/cognitive-complexity: ^1.0
- tomasvotruba/type-coverage: ^2.0
README
Easily profile of parts of your application/code and measure the performance to expose the bottlenecks
Installation
You can install the package via composer:
composer require sandermuller/stopwatch
Usage
Start the stopwatch
use SanderMuller\Stopwatch\Stopwatch; $stopwatch = Stopwatch::start();
Add a lap/checkpoint
use SanderMuller\Stopwatch\Stopwatch; $stopwatch = Stopwatch::start(); $stopwatch->checkpoint('First checkpoint'); // Or $stopwatch->lap('Second checkpoint');
Display the total run duration
use SanderMuller\Stopwatch\Stopwatch; $stopwatch = Stopwatch::start(); // Do something echo $stopwatch->toString(); // or echo (string) $stopwatch; // Echoes something like: 116ms
Render as HTML
Render a neat HTML output showing the total execution time, each checkpoint and the time between each checkpoint.
The checkpoints that took up most of the time will be highlighted.
use SanderMuller\Stopwatch\Stopwatch; $stopwatch = Stopwatch::start(); // Do something $stopwatch->checkpoint('First checkpoint'); // Do something more $stopwatch->checkpoint('Second checkpoint'); echo $stopwatch->toHtml(); // Or in Laravel {{ $stopwatch }}
Manually stop the stopwatch
You can manually stop the stopwatch, but it will also stop automatically when the Stopwatch output is used (e.g. when you echo the Stopwatch object or call ->totalRunDuration()
).
use SanderMuller\Stopwatch\Stopwatch; $stopwatch = Stopwatch::start(); // Do something $stopwatch->stop(); // Do something you don't want to measure // Finally render the output echo $stopwatch->toHtml();