定制 vitorsreis/extend-benchmark 二次开发

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

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

vitorsreis/extend-benchmark

最新稳定版本:1.0.5

Composer 安装命令:

composer require vitorsreis/extend-benchmark

包简介

Simple Benchmark for PHP 8.2+

README 文档

README

Latest Stable Version PHP Version Require License Total Downloads Repo Stars

With this simple and elegant benchmark, you can create multiple tests with multiple callbacks at once and output tests in real time. Unit tests have passed on versions: 8.2 and 8.3

Install

composer require vitorsreis/extend-benchmark

Usage

require_once __DIR__ . '/vendor/autoload.php';

use VSR\Extend\Benchmark;

// 1. Benchmark agent
$agent = new Benchmark(
    'My benchmark tests',
    // [optional] 'My Comment',
    // [optional] Printer, if not informed, will be used the default printers ( Printer/Console | Printer/Html ) 
);

// 2. Create benchmarks
$benchmark1 = $agent
    ->createBenchmark(
        'My Benchmark 1',
        // [optional] 'Test 1 Comment',
        // [optional] <iterations>, force number of interactions for this test
    );

// 3. Add tests
$benchmark1->addTest(
    'Test 1',
    [ 'return' => 'RESULT1-OK' ], // Expected result "RESULT1-OK"
    fn() => 'RESULT1-OK', // Callback 1
);
$benchmark1->addTest(
    'Test 2',
    [ 'return' => 'RESULT2-OK' ], // Expected result "RESULT1-OK"
    fn() => 'RESULT2', // Callback 1 - returns "RESULT2"
    fn($__partial) => "$__partial[return]-OK", // Callback 2 - Merge with callback 1, returns "RESULT2-OK"
);

// 4. Execute benchmarks and tests
$agent->execute(
    // [optional, default 1] <iterations>, number of interactions for all tests
);
• Expect test types
null // Use null to any resultarray( // or array of expected results, if omitted, the test will be considered successful
    "skipped"   => string, // [optional] custom skipped message print

    "type"   => string, // [optional] output|throw|skipped or return value type
    
    "return" => mixed, // [optional] accept callback return value
    
    "output" => null, // [optional] not accept callback output

    "output" => string, // [optional] accept callback output
    
    "throw"  => null, // [optional] not accept callback throw
    
    "throw"  => string, // [optional] accept callback throw class
    
    "throw"  => array( // [optional] accept callback throw by class, message, code, file and line
        "class" => string,   # [optional] accept callback throw class
        "message" => string, # [optional] accept callback throw message
        "code" => int,       # [optional] accept callback throw code
        "file" => string,    # [optional] accept callback throw file
        "line" => int        # [optional] accept callback throw line
    )
)
• There are 2 magic arguments that are automatically filled when detected in the call.
// Current interaction number
$__interaction = int

// Partial test returns
$__partial = array(
    "type"   => string, // pending|output|throw|skipped or return value type
    "return" => mixed,
    "output" => null|string,
    "throw"  => null|array(
        "class"   => string,
        "message" => string,
        "code"    => int,
        "line"    => int,
        "file"    => string
    )
)
If necessary, arguments can be added to the mapping to call the "__construct" and method. The smart populate looks for required arguments and fills them in recursively, regardless of position, so there's no argument overflow.
$benchmark = $agent->createBenchmark('Test 1');

// by methods
$benchmark->argsByMethods([
    'arg1' => 'value1',
    'arg2' => 'value2',
    'arg3' => 'value3' // ignored
]);

$benchmark->addTest(
    '<title>',
    '<expected result>', // Expected result
    fn ($arg1, $__interaction, $arg2, $__partial) => ..., // arrow function
)
Supported callbacks
$benchmark->test(
    '<title>',
    '<expected result>',
    
    # Supported callbacks ↓↓↓
    
    "strlen", // native function name
    
    "myFunction", // function name
    
    function () { ... }, // anonymous function
    
    fn () => ..., // arrow function
    
    "MyClass::myMethod", // class method, "__construct" will be called before the method
    
    [ MyClass::class, "myMethod" ], # class method, "__construct" will be called before the method
    
    "MyClass::myStaticMethod", // class static method
    
    [ MyClass::class, "myStaticMethod" ], # class static method
    
    [ new MyClass(), "myMethod" ], // object, myMethod
    
    [ $myObject, "myMethod" ], # object, myMethod
    
    new MyClass(), # object, __invoke
    
    $myObject, # object, __invoke
    
    [ new MyClass(), "myStaticMethod" ], // object, myStaticMethod
    
    [ $myObject, "myStaticMethod" ], # object, myStaticMethod
);

vitorsreis/extend-benchmark 适用场景与选型建议

vitorsreis/extend-benchmark 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 08 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「performance」 「benchmark」 「comparer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 vitorsreis/extend-benchmark 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 vitorsreis/extend-benchmark 我们能提供哪些服务?
定制开发 / 二次开发

基于 vitorsreis/extend-benchmark 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-24