sandermuller / stopwatch
用于测量 Laravel 和 PHP 项目执行时间的计时器(性能分析代码)
v0.1.4
2024-08-23 23:10 UTC
Requires
- php: ^8.2
- illuminate/collections: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
- nesbot/carbon: ^2|^3
- symfony/var-dumper: ^6|^7
Requires (Dev)
- laravel/pint: ^1.15
- nunomaduro/collision: ^8.1
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^1.10
- phpstan/phpstan-deprecation-rules: ^1.2
- phpstan/phpstan-strict-rules: ^1.6
- rector/rector: ^1.0
- roave/security-advisories: dev-latest
- tomasvotruba/type-coverage: ^0.3.1
README
轻松分析应用程序/代码的各个部分并测量性能以揭示瓶颈
安装
您可以通过 composer 安装此包
composer require sandermuller/stopwatch
使用方法
启动计时器
use SanderMuller\Stopwatch\Stopwatch; $stopwatch = Stopwatch::start();
添加圈/检查点
use SanderMuller\Stopwatch\Stopwatch; $stopwatch = Stopwatch::start(); $stopwatch->checkpoint('First checkpoint'); // Or $stopwatch->lap('Second checkpoint');
显示总运行时间
use SanderMuller\Stopwatch\Stopwatch; $stopwatch = Stopwatch::start(); // Do something echo $stopwatch->toString(); // or echo (string) $stopwatch; // Echoes something like: 116ms
以 HTML 格式渲染
渲染整洁的 HTML 输出,显示总执行时间、每个检查点和每个检查点之间的时间。
耗时最多的检查点将被突出显示。
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 }}
手动停止计时器
您可以手动停止计时器,但当使用 Stopwatch 输出时(例如,当您输出 Stopwatch 对象或调用 ->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();