定制 n0zzy/phpbenchmark 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

n0zzy/phpbenchmark

最新稳定版本:0.3.0

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  |

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-07