phpunit/php-timer
Composer 安装命令:
composer require phpunit/php-timer
包简介
Utility class for timing
关键字:
README 文档
README
Utility class for timing things, factored out of PHPUnit into a stand-alone component.
Installation
You can add this library as a local, per-project dependency to your project using Composer:
composer require phpunit/php-timer
If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:
composer require --dev phpunit/php-timer
Usage
Basic Timing
require __DIR__ . '/vendor/autoload.php'; use SebastianBergmann\Timer\Timer; $timer = new Timer; $timer->start(); foreach (\range(0, 100000) as $i) { // ... } $duration = $timer->stop(); var_dump(get_class($duration)); var_dump($duration->asString()); var_dump($duration->asSeconds()); var_dump($duration->asMilliseconds()); var_dump($duration->asMicroseconds()); var_dump($duration->asNanoseconds());
The code above yields the output below:
string(32) "SebastianBergmann\Timer\Duration"
string(9) "00:00.002"
float(0.002851062)
float(2.851062)
float(2851.062)
int(2851062)
Resource Consumption
Explicit duration
require __DIR__ . '/vendor/autoload.php'; use SebastianBergmann\Timer\ResourceUsageFormatter; use SebastianBergmann\Timer\Timer; $timer = new Timer; $timer->start(); foreach (\range(0, 100000) as $i) { // ... } print (new ResourceUsageFormatter)->resourceUsage($timer->stop());
The code above yields the output below:
Time: 00:00.002, Memory: 6.00 MB
Duration since PHP Startup (using unreliable $_SERVER['REQUEST_TIME_FLOAT'])
require __DIR__ . '/vendor/autoload.php'; use SebastianBergmann\Timer\ResourceUsageFormatter; foreach (\range(0, 100000) as $i) { // ... } print (new ResourceUsageFormatter)->resourceUsageSinceStartOfRequest();
The code above yields the output below:
Time: 00:00.002, Memory: 6.00 MB
phpunit/php-timer 适用场景与选型建议
phpunit/php-timer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 912.1M 次下载、GitHub Stars 达 7.74k, 最近一次更新时间为 2012 年 09 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「timer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 phpunit/php-timer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 phpunit/php-timer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 phpunit/php-timer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Native PHP Library to profile PHP code.
Drop-dead simple execution time measurements
Utility class for timing
Simple handler for ReactPHP timers
For functions benchmarking, contain counters and timers classes.
时间助手
统计信息
- 总下载量: 912.1M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7806
- 点击次数: 27
- 依赖项目数: 139
- 推荐数: 4
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2012-09-18