miladhspr / performance-analyzer
一个用于测量代码段执行时间的 PHP 测试类。
v0.0.2
2024-03-08 13:36 UTC
Requires
- php: ^8.0
README
PerformanceAnalyzer 是一个 PHP 类,可以帮助您测量 PHP 应用程序中代码段或操作的执行时间。它提供了开始和停止计时器、测量回调函数的执行时间以及以人类可读的格式显示执行时间的方法。
安装
您可以通过 Composer 安装 PerformanceAnalyzer
composer require miladhspr/performance-analyzer
用法
开始和结束计时器
要测量代码段的执行时间,您可以在代码段之前开始计时,之后结束
use MiladHspr\PerformanceAnalyzer; PerformanceAnalyzer::startTimer(); // Your code segment or operation goes here PerformanceAnalyzer::endTimer();
测量回调函数的执行时间
您也可以使用 measureExecutionTime
方法来测量回调函数的执行时间
use MiladHspr\PerformanceAnalyzer; PerformanceAnalyzer::measureExecutionTime(function () { // Your callback function or code segment goes here });
示例
以下是一个演示 PerformanceAnalyzer 用法的简单示例
use MiladHspr\PerformanceAnalyzer; PerformanceAnalyzer::startTimer(); // Code segment or operation to measure goes here PerformanceAnalyzer::endTimer();
输出
PerformanceAnalyzer 以人类可读的格式显示执行时间,包括毫秒、微秒或纳秒,具体取决于操作的持续时间。
许可
PerformanceAnalyzer 是开源软件,许可协议为 MIT 许可协议。