n0zzy/phpbenchmark
Composer 安装命令:
composer require n0zzy/phpbenchmark
包简介
Simple Php Benchmark
README 文档
README
Install (composer)
composer require n0zzy/phpbenchmark
Run (for terminal/console)
php your_php_script_benchmark
Settings (Example Run for html)
#!/usr/bin/php <?php require __DIR__ . '/vendor/autoload.php'; use N0zzy\PhpBenchmark\Attributes\Benchmark; use N0zzy\PhpBenchmark\Attributes\BenchmarkMethod; use N0zzy\PhpBenchmark\PhpBenchmark; use N0zzy\PhpBenchmark\PhpBenchmarkSettings; use N0zzy\PhpBenchmark\Services\OutputEnum; use N0zzy\PhpBenchmark\Services\MemoryEnum; #[PhpBenchmarkSettings(settings: [ 'output' => OutputEnum::Html, 'memory' => MemoryEnum::MEDIUM, 'gc' => false ])] class Setting {} class A { #[Benchmark(count: 100)] #[BenchmarkMethod([ 'class' => A::class, 'method' => 'a' ])] private function a($class, $method) { static $a = 0; $a++; $b = $class . '::' . $method; } } new PhpBenchmark(Setting::class);
Example №1: adding a class(es) and methods for the test
#!/usr/bin/php <?php require __DIR__ . '/vendor/autoload.php'; use N0zzy\PhpBenchmark\Attributes\Benchmark; use N0zzy\PhpBenchmark\Attributes\BenchmarkMemory; use N0zzy\PhpBenchmark\Attributes\BenchmarkMethod; use N0zzy\PhpBenchmark\PhpBenchmark; #[Benchmark( count: 10 )] #[BenchmarkMemory( limit: 500 )] class BenchmarkTest { private string $a = ""; private int $b = 0; #[Benchmark(count: 100)] public function test1(): void { $this->b = rand(1, 1000); $this->a = str_repeat( 'a', $this->b ); } #[Benchmark(count: 100)] public function test2(): void { $this->b = rand(1, 1000); $this->a = str_repeat( 'a', $this->b ); } } new PhpBenchmark( BenchmarkTest::class );
Example №2: adding only methods for the test
#!/usr/bin/php <?php require __DIR__ . '/vendor/autoload.php'; use N0zzy\PhpBenchmark\Attributes\Benchmark; use N0zzy\PhpBenchmark\Attributes\BenchmarkGC; use N0zzy\PhpBenchmark\Attributes\BenchmarkMemory; use N0zzy\PhpBenchmark\Attributes\BenchmarkMethod; use N0zzy\PhpBenchmark\PhpBenchmark; class A { #[Benchmark(count: 10)] #[BenchmarkMethod([ 'class' => A::class, 'method' => 'a' ])] private function a($class, $method) { static $a = 0; $a++; $b = $class . '::' . $method; } } new PhpBenchmark();
Results
|__Name________________________|__Memory(RSS, kb)________|__Count_____________|__Time(min, s/ns)___|__Time(max, s/ns)___|__Time(avg, s/ns)___|
| Php Memory Limit: 500M
| (c) BenchmarkTest | 0.078125 | 10 | 0 / 5100 | 0 / 9100 | 0 / 6770 |
| (m) test1 | 55.9296875 | 100 | 0 / 400 | 0.0215 / 21490200 | 0.0002 / 215557 |
| (m) test2 | 56.3828125 | 100 | 0 / 300 | 0 / 14500 | 0 / 662 |
|__Name________________________|__Memory(RSS, kb)________|__Count_____________|__Time(min, s/ns)___|__Time(max, s/ns)___|__Time(avg, s/ns)___|
| (c) A | 0 | 0 | NaN | NaN | NaN |
| (m) a | 0.7109375 | 10 | 0 / 300 | 0 / 8900 | 0 / 1260 |
n0zzy/phpbenchmark 适用场景与选型建议
n0zzy/phpbenchmark 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 02 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 n0zzy/phpbenchmark 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 n0zzy/phpbenchmark 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-07