esi/bench

用于基准测试的微型PHP库

v3.1.1 2024-06-13 13:35 UTC

This package is auto-updated.

Last update: 2024-09-23 01:49:03 UTC


README

Build Status Code Coverage Scrutinizer Code Quality Continuous Integration Type Coverage Psalm Level Latest Stable Version Downloads per Month License

Bench 是一个用于基准测试的PHP微型库。

致谢/信用

Benchdevster/ubench 的分支,并使用与原始存储库相同的许可(MIT)。感谢他们以及所有贡献者!

安装

Composer

运行以下命令来安装该软件包

composer require esi/bench:~3.0.0

用法

require_once 'vendor/autoload.php';

$bench = new Bench;

$bench->start();

// Execute some code

$bench->end();

// Get elapsed time and memory.
echo $bench->getTime(); // 156ms or 1.123s
echo $bench->getTime(true); // elapsed microtime in float
echo $bench->getTime(false, '%d%s'); // 156ms or 1s

echo $bench->getMemoryPeak(); // 152B or 90.00Kb or 15.23Mb
echo $bench->getMemoryPeak(true); // memory peak in bytes
echo $bench->getMemoryPeak(false, '%.3f%s'); // 152B or 90.152Kb or 15.234Mb

// Returns the memory usage at the end mark.
echo $bench->getMemoryUsage(); // 152B or 90.00Kb or 15.23Mb

// Runs `Bench::start()` and `Bench::end()` around a callable.
// Accepts a callable as the first parameter.  Any additional parameters will be passed to the callable.
$result = $bench->run(function (int $x): int {
    return $x;
}, 1);
echo $bench->getTime();

关于

要求

  • Bench 需要 PHP 8.2.0 或更高版本。

提交错误和功能请求

错误和功能请求在 GitHub 上跟踪

问题是最快报告错误的方式。如果您发现错误或文档错误,请首先检查以下内容

  • 该错误尚未有已打开的问题
  • 该问题尚未被解决(例如,在已关闭的问题中)

贡献

查看 CONTRIBUTING

作者

Eric Sizemore - admin@secondversion.com - https://www.secondversion.com

许可

Bench 采用 MIT 许可证 - 请参阅 LICENSE.md 文件以获取详细信息。