asika/ simple-benchmark
PHP 简单基准测试框架
3.1.0
2023-10-28 12:47 UTC
Requires
- php: >=8.0
- symfony/console: ^5.0||^6.0||^7.0
- symfony/stopwatch: ^5.0||^6.0||^7.0
Requires (Dev)
- windwalker/utilities: ^4.0
This package is auto-updated.
Last update: 2024-08-28 14:34:14 UTC
README
通过 Composer 安装
composer global require asika/simple-benchmark
入门
在终端中输入 benchmark
或 sb
。
sb
输出将如下
PHP Simple Benchmark Framework - version: 2.0.0-beta
------------------------------------------------------------
[sb Help]
Help of Simple Benchmark.
Usage:
sb <command> [option]
Options:
-h | --help Display this help message.
-q | --quiet Do not output any message.
-v | --verbose Increase the verbosity of messages.
--ansi Set 'off' to suppress ANSI colors on unsupported terminals.
Commands:
run Run benchmark
create Create a task file.
Use `benchmark create TaskName` to generate a new task sample file to /tasks folder.
Use `benchmark run TaskFile.php [times]` to run benchmark
创建任务文件
sb create TaskName
将在当前文件夹生成一个名为 TaskName.php
的文件。
打开 TaskName.php
,您将看到
<?php /** @var \SimpleBenchmark\Benchmark $benchmark */
您可以通过 addTask()
来执行基准测试。
<?php /** @var \SimpleBenchmark\Benchmark $benchmark */ $benchmark->addTask('task1-md5', function() { md5(uniqid()); }); $benchmark->addTask('task2-sha1', function() { sha1(uniqid()); });
运行基准测试
使用此命令运行基准测试
sb run TaskName.php
输出将如下
Benchmark Result
---------------------------------------------
Run 10,000 times
task1-md5:
- Time: 0.0104s
- Memory: 2048kb
task2-sha1:
- Time: 0.0101s
- Memory: 2048kb
您可以在第二个参数中设置次数(默认为 10000)
php benchmark run TaskName.php 15000