tankfairies / benchmark
基准代码
1.3
2024-03-19 23:21 UTC
Requires
- php: ^8.2
Requires (Dev)
- codeception/codeception: ^5.1
- codeception/module-asserts: ^3.0
- codeception/module-phpbrowser: ^3.0
- dg/bypass-finals: ^1.6
README
基准测试
提供在代码块上进行简单性能测试的能力。
安装
使用Composer安装
composer require tankfairies/benchmark
用法
服务器详情
这将输出运行性能测试的机器上的基本详情数组。
对于服务器详情: -
$server = new Server(); $details = $server->getDetails();
输出示例: -
Array ( [PHP] => 8.2.16 [Platform] => Darwin [Arch] => arm64 [Max memory usage] => 128M [OPCache status] => disabled [OPCache JIT] => disabled/unavailable [PCRE JIT] => enabled [XDebug extension] => disabled )
对于已安装的扩展: -
$server = new Server(); $extensions = $server->getInstalledExtensions();
输出示例: -
Array ( [0] => Core [1] => date [2] => libxml [3] => openssl [4] => pcre [5] => sqlite3 [6] => zlib [7] => bcmath ...
计时器
处理基准测试的时间记录。
基准测试
将您要测试的代码调用或放入匿名函数中,例如: -
$func = function () { rand(1, 100000); };
按以下方式设置基准测试: -
$benchmark = new Benchmark(new Stopwatch()); $completion = $benchmark ->multiplier(200000, 5) ->script($func) ->run();
您可以为运行定义自己的标准,例如上述示例将测试200000次,共5个循环。这将产生5组以秒为格式的结果: -
Array ( [1] => 0.1699 [2] => 0.1642 [3] => 0.1641 [4] => 0.1643 [5] => 0.1645 )
上述显示了每次200k运行执行的秒数。
版权和许可
tankfairies/benchmark 库版权所有(c)2019 Tankfairies(《https://tankfairies.com》),并许可在MIT许可(MIT)下使用。