angle/chrono
Composer 安装命令:
composer require angle/chrono
包简介
The easiest way to measure PHP code execution time.
README 文档
README
The easiest way to measure PHP code execution time.
Introduction
Every time I need to benchmark something, I find myself re-inventing the wheel and do manual time calculations. This hurts my productivity. I wanted a simple little package that is very easy to use that I can go to whenever I need to measure execution time in PHP.
- Easy to remember
- 100% tested
- Framework agnostic
- No dependencies
Installation
composer require angle/chrono
Documentation
This statement is implicitly used above any of the following examples:
use Angle\Chrono;
The shortest way to benchmark your code is to use the benchmark method:
echo Chrono::benchmark(function () { sleep(1); });
Output:
Time: 1 second (1002 ms)
By default, it invokes the 'meter' method which pretty-prints the output. Optionally, you can pass a second parameter to invoke any available formatting methods (ms, seconds, minutes):
echo Chrono::benchmark(function () { sleep(1); }, 'ms');
Output:
1002
Manual usage:
Chrono::start(); // Do something... echo Chrono::stop(); // 2.42424242 (seconds)
To get formatted output, use the 'meter' method:
Chrono::start(); // Compute stuff echo Chrono::meter(); // Time: 0.42 seconds (4242 ms)
You can access elapsed time whenever you need, in various formats:
echo Chrono::elapsed(); // 0.42424242 echo Chrono::seconds(); // 0.43 echo Chrono::ms(); // 4243
You can pause and resume the chronometer:
Chrono::start(); sleep(1); Chrono::pause(); sleep(3); // Will be ignored Chrono::resume(); sleep(1); print Chrono::meter(); // Time: 2 seconds (2001 ms)
If you are running many benchmarks, it may be a good idea to add a description to them:
Chrono::describe('Query with joints'); Chrono::start(); // Run the query print Chrono::meter();
Output:
Query with joints | 1.43 seconds (1424 ms)
Warning: if you prefer to use the shorthand benchmark method, make sure to call the describe method within your benchmark:
Chrono::benchmark(function () { Chrono::describe('Task'); // Do your thing });
For a more detailed overview, please refer to the test suite.
Credits
This implementation is inspired by David Walsh's timer class.
Contributing
Improvements are welcome! Feel free to submit pull requests.
Licence
MIT
Copyright © 2019 Angle Software
angle/chrono 适用场景与选型建议
angle/chrono 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16.45k 次下载、GitHub Stars 达 28, 最近一次更新时间为 2019 年 03 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 angle/chrono 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 angle/chrono 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 16.45k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 29
- 点击次数: 25
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-03-11