almasmurad/stopwatch
Composer 安装命令:
composer require almasmurad/stopwatch
包简介
Component for measuring code execution time
README 文档
README
PHP tool that measures code execution time.
Usage
// create Stopwatch $stopwatch = new Almasmurad\Stopwatch\Stopwatch(); // start measuring the first step $stopwatch->start('code section #1'); //... // start measuring the second step $stopwatch->step('code section #2'); //... // start measuring the third step $stopwatch->step('code section #3'); //... // finish measuring $stopwatch->finish(); // output the report $stopwatch->report();
As a result, the following report gets into the standard output:
Start | 06:55:14.123
-----------------|--------------
code section #1 | 0.198 s
code section #2 | 0.209 s
code section #3 | 1.200 s
-----------------|--------------
Summary | 1.607 s
Minimal Usage
$stopwatch = new Almasmurad\Stopwatch\Stopwatch(); //... (measured code) $stopwatch->report();
As a result, the following report gets into the standard output:
Start | 06:55:14.123
---------|--------------
Summary | 0.198 s
Output Report to File
$stopwatch->reportToFile(__DIR__.'/report.txt');
Report will be written to a file, and nothing will get into the standard output. If the file already exists, the report will replace its contents. In order for the report to append the contents of the file, use another method:
$stopwatch->reportToFileInAppendMode(__DIR__.'/report.txt');
Access to the Report Components
Instead of outputting the report to a standard stream or file, you can access its components:
// getting the report object $report = $stopwatch->getReport(); // general indicators $start = $report->getStart()->getTimestamp(); // stopwatch start time $finish = $report->getFinish()->getTimestamp(); // stopwatch finish time $elapsed = $report->getElapsed()->getSeconds(); // time of the entire stopwatch operation // indicators of first code section $step1_start = $report->getStepByIndex(0)->getStart()->getTimestamp(); $step1_finish = $report->getStepByIndex(0)->getFinish()->getTimestamp(); $step1_elapsed = $report->getStep('code section #1')->getElapsed()->getSeconds(); // all of code sections foreach ($report->getSteps() as $step){ //... }
You can read more about the report object in the section 'Report object'
Learn More
almasmurad/stopwatch 适用场景与选型建议
almasmurad/stopwatch 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 02 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 almasmurad/stopwatch 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 almasmurad/stopwatch 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-09