nullform / app-timer
具有嵌套间隔的计时器,执行时间测量
v2.1.0
2024-03-04 10:05 UTC
Requires
- php: >=7.1
- ext-bcmath: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^7.5
README
PHP应用程序的嵌套间隔计时器。
安装
composer require nullform/app-timer
使用方法
基本使用
use Nullform\AppTimer; $timer = new AppTimer\Timer("New timer"); $timer->start("First interval"); // Some code... $interval = $timer->stop(); // Instance of Interval $timer->start("Second interval"); // Some code... $duration = $timer->stop()->duration; // float $report = $timer->report(); // Instance of Report
嵌套间隔
您可以在其他间隔内创建新的(嵌套)间隔。
$timer->start("First interval"); // Parent interval $timer->start("First nested interval"); // Some code... $timet->stop(); // Stop first nested interval $timer->start("Second nested interval"); // Some code... $timet->stop(); // Stop second nested interval $timer->stop(); // Stop parent interval $report = $timer->report(); // Instance of Report
计时器/间隔的附加信息
您可以为计时器/间隔添加附加信息,使其反映在报告中。
$timer = new AppTimer\Timer("New timer", ['Size' => "XXL"]); $timer->start("New interval", ['Color' => "Red"]);
报告
报告可以生成为可读的字符串或JSON格式。您可以将报告保存到文件中。
// Create new timer $timer = new AppTimer\Timer("New timer"); // Report file options $timer->report_filename = "AppTimerReport.log"; $timer->report_dir = dirname(__FILE__); $timer->report_file_append = true; $timer->start("New interval"); // ... $timer->stop(); // Create report $report = $timer->report(); // Instance of Report $report_json = $report->toJSON(); $report_string = $report->toString();
方法
计时器
- Timer::__construct(string $description = "", array $extras = [])
- Timer::start(string $description, array $extras = []): Interval
- Timer::stop(array $extras = []): ?Interval
- Timer::stopAll(): void
- Timer::report(): Report
Interval
- Interval::extras(): Extras
Extras
- Extras::add(string $key, string $value): int
- Extras::remove(string $key): int
- Extras::get(): array
- Extras::getOne(string $key): ?string
报告
- Report::longestInterval(): ?Interval
- Report::toString(): string
- Report::toJSON(): string
- Report::extras(): Extras