dragon-code/runtime-comparison
最新稳定版本:v1.5.1
Composer 安装命令:
composer require dragon-code/runtime-comparison
包简介
Simple comparison of code execution speed between different options
README 文档
README
Installation
To get the latest version of The Dragon Code: Benchmark, simply require the project using Composer:
composer require dragon-code/benchmark --dev
Or manually update require-dev block of composer.json and run composer update console command:
{
"require-dev": {
"dragon-code/benchmark": "^1.0"
}
}
Using
Note
The result of the execution is printed to the console, so make sure you call the code from the console.
use DragonCode\Benchmark\Benchmark; (new Benchmark())->compare( fn () => /* some code */, fn () => /* some code */, ); (new Benchmark())->compare([ fn () => /* some code */, fn () => /* some code */, ]); (new Benchmark())->compare([ 'foo' => fn () => /* some code */, 'bar' => fn () => /* some code */, ]);
Result example:
------- ------------- -------------
# 0 1
------- ------------- -------------
1 11.3845 ms 15.565 ms
2 14.92 ms 14.8241 ms
3 14.812 ms 15.2948 ms
4 15.3211 ms 14.9243 ms
5 15.045 ms 15.4147 ms
6 15.3918 ms 15.1484 ms
7 14.6678 ms 14.0797 ms
8 14.7602 ms 14.613 ms
9 14.9372 ms 15.6712 ms
...
100 15.2036 ms 14.6706 ms
------- ------------- -------------
min 11.3845 ms 14.0797 ms
max 15.3918 ms 15.6712 ms
avg 14.64432 ms 15.02058 ms
------- ------------- -------------
Order - 1 - - 2 -
------- ------------- -------------
When measuring the average value among the results, when more than 10 iterations are used, the final data is filtered by peak values. The calculation of the 10% of the lowest and 10% of the highest values is excluded from the total result, thus the final data becomes cleaner and less dependent on any external factors.
Iterations Count
By default, the benchmark performs 100 iterations per callback, but you can change this number by calling the iterations method:
use DragonCode\Benchmark\Benchmark; (new Benchmark()) ->iterations(5) ->compare( fn () => /* some code */, fn () => /* some code */, );
If the passed value is less than 1, then one iteration will be performed for each callback.
Without Data
If you want to see only the summary result of the run time without detailed information for each iteration, then you can call the withoutData method, which will display only the
summary information:
use DragonCode\Benchmark\Benchmark; (new Benchmark()) ->withoutData() ->compare([ 'foo' => fn () => /* some code */, 'bar' => fn () => /* some code */, ]);
Result example:
------- ------------- -------------
# foo bar
------- ------------- -------------
min 11.3845 ms 14.0797 ms
max 15.3918 ms 15.6712 ms
avg 14.64432 ms 15.02058 ms
------- ------------- -------------
Order - 1 - - 2 -
------- ------------- -------------
Note
If the option to display detailed information is enabled (without using the
withoutDatamethod) and more than 1000 iterations are requested, then the output of detailed information will be forcibly disabled, since there will be absolutely no point in it with a significantly increasing load on the computer.
Round Precision
By default, the script does not round measurement results, but you can specify the number of decimal places to which rounding can be performed.
For example:
use DragonCode\Benchmark\Benchmark; (new Benchmark()) ->iterations(5) ->round(2) ->compare( fn () => /* some code */, fn () => /* some code */, );
Result example:
------- ---------- ----------
# 0 1
------- ---------- ----------
1 12.22 ms 14.65 ms
2 14.54 ms 15.37 ms
3 15.26 ms 14.37 ms
4 15.07 ms 14.73 ms
5 14.67 ms 14.74 ms
------- ---------- ----------
min 12.22 ms 14.37 ms
max 15.26 ms 15.37 ms
avg 14.35 ms 14.77 ms
------- ---------- ----------
Order - 1 - - 2 -
------- ---------- ----------
License
This package is licensed under the MIT License.
dragon-code/runtime-comparison 适用场景与选型建议
dragon-code/runtime-comparison 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 7, 最近一次更新时间为 2023 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「time」 「speed」 「timer」 「comparison」 「runtime」 「comparator」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dragon-code/runtime-comparison 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dragon-code/runtime-comparison 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dragon-code/runtime-comparison 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Native PHP Library to profile PHP code.
Tools to convert between .NET and PHP date formats
Adds the EDTF data type to Wikibase
Date component is a set of methods to help with the manipulation of dates.
Drop-dead simple execution time measurements
Bureaux A Partager Edit - Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js
统计信息
- 总下载量: 20
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-03