承接 bfg/speed-test 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

bfg/speed-test

Composer 安装命令:

composer require bfg/speed-test

包简介

Designed for approximate estimation of the time of code execution by the number of iterations

README 文档

README

Designed for approximate estimation of the time of code execution by the number of iterations.

Install

composer require bfg/speed-test --dev

Create bench check

Suppose that we need to check how long it will work out the bcrypt password encryption function. Run the following command:

php artisan make:bench bcrypt -t 10 -l "bcrypt(time());"

And launch the test:

php artisan benchmark bcrypt

Config publish

php artisan vendor:publish --tag=speed-test

Commands

make:bench

Speed test maker

Usage:
  make:bench [options] [--] [<test>]

Arguments:
  test                             The test name

Options:
  -d, --description[=DESCRIPTION]  The description of test
  -t, --times[=TIMES]              Number of iterations [default: "10"]
  -l, --line[=LINE]                Code line in the icted function [default: "//"]

Your test will be created in the tests/Benchmark folder, you can change this in config speed-test.dir.

Meaning Description and the number of iterations are indicated in the dock of the test block.

benchmark

Speed test runner

Usage:
  benchmark [<test>]

Arguments:
  test                  The name of the test case [Optional].
  
Options:
  -t, --times[=TIMES]   Number of iterations for all
  -l, --ls              Show list of tests  

You can specify the class name as a test name, or specify the name of the class together with the "@" method.

Example

Show list my benchmarks:

php artisan benchmark -l

Output:

+-------------------------+------------------------------+-----------------------+-------+
| Class                   | Test                         | Description           | Times |
+-------------------------+------------------------------+-----------------------+-------+
| Tests\Benchmark\Bcrypt  | bcrypt@speed1                | Bcrypt tester         | 10    |
| Tests\Benchmark\Bcrypt  | bcrypt@speed2                | Double bcrypt tester  | 5     |
| Tests\Benchmark\Bcrypt2 | bcrypt2@speed1               | Bcrypt tester         | 10    |
| Tests\Benchmark\Bcrypt2 | bcrypt2@speed2               | Bcrypt tester         | 10    |
| Tests\Benchmark\Bcrypt2 | bcrypt2@speed3               | Bcrypt tester         | 10    |
| Tests\Benchmark\Bcrypt2 | bcrypt2@speed4               | Bcrypt tester         | 10    |
| Tests\Benchmark\Bcrypt2 | bcrypt2@speed5               | Bcrypt tester         | 10    |
| Tests\Benchmark\Bcrypt2 | bcrypt2@speed6               | Bcrypt tester         | 10    |
| Tests\Benchmark\Bcrypt2 | bcrypt2@speed7               | Bcrypt tester         | 10    |
| Tests\Benchmark\Text    | text@file_lines_get_contents | Text Speed 1          | 1000  |
| Tests\Benchmark\Text    | text@lang_in_text            | lang_in_text          | 1000  |
| Tests\Benchmark\Text    | text@tag_replace             | tag_replace           | 1000  |
| Tests\Benchmark\Text    | text@assoc                   | Assoc                 | 1000  |
| Tests\Benchmark\Text    | text@array_dots_uncollapse   | array_dots_uncollapse | 1000  |
| Tests\Benchmark\XsTest  | xs_test@speed1               | My test               | 1000  |
+-------------------------+------------------------------+-----------------------+-------+

I have benchmark Text:

php artisan benchmark text

Output:

Text Speed 1
 1000/1000 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%  1 sec/1 sec  26.0 MiB 

lang_in_text
 1000/1000 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% < 1 sec/< 1 sec 26.0 MiB 

tag_replace
 1000/1000 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%  1 sec/1 sec  26.0 MiB 

Assoc
 1000/1000 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% < 1 sec/< 1 sec 26.0 MiB 

array_dots_uncollapse
 1000/1000 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% < 1 sec/< 1 sec 26.0 MiB 


+------------+--------------------+-------------------+----------------+-----------------+--------------+----------------------------+
| Test count | Total test seconds | Total test memory | Usage memory   | Free memory     | Memory limit | Current \ Total used % CPU |
+------------+--------------------+-------------------+----------------+-----------------+--------------+----------------------------+
| 5          | 1.3933 sec         | 47.3203125 kb     | 24.48337555 mb | 103.51662445 mb | 128 mb       | 2.01904296875 \ 0          |
+------------+--------------------+-------------------+----------------+-----------------+--------------+----------------------------+
+------------------------------+-----------------------+-------+-----------------------+-------------------------------+------------+
| Test                         | Description           | Times | In work               | Used memory                   | Used % CPU |
+------------------------------+-----------------------+-------+-----------------------+-------------------------------+------------+
| text@file_lines_get_contents | Text Speed 1          | 1000  | 0.2247 | 0.000225 sec | 1.078125 kb   | 0.00107813 kb | 0          |
| text@lang_in_text            | lang_in_text          | 1000  | 0.5282 | 0.000528 sec | 24.5 kb       |     0.0245 kb | 0          |
| text@tag_replace             | tag_replace           | 1000  | 0.337  | 0.000337 sec | 21.7421875 kb | 0.02174219 kb | 0          |
| text@assoc                   | Assoc                 | 1000  | 0.153  | 0.000153 sec | 0.0 b         |         0.0 b | 0          |
| text@array_dots_uncollapse   | array_dots_uncollapse | 1000  | 0.1504 |  0.00015 sec | 0.0 b         |         0.0 b | 0          |
+------------------------------+-----------------------+-------+-----------------------+-------------------------------+------------+

Or I need to check text@assoc, and I want call this bench 1 time:

php artisan benchmark text@assoc -t 1

Output:

Assoc
 1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% < 1 sec/< 1 sec 26.0 MiB 


+------------+--------------------+-------------------+----------------+-----------------+--------------+----------------------------+
| Test count | Total test seconds | Total test memory | Usage memory   | Free memory     | Memory limit | Current \ Total used % CPU |
+------------+--------------------+-------------------+----------------+-----------------+--------------+----------------------------+
| 1          | 0.0022 sec         | 1.078125 kb       | 24.42333984 mb | 103.57666016 mb | 128 mb       | 2.41650390625 \ 0          |
+------------+--------------------+-------------------+----------------+-----------------+--------------+----------------------------+
+------------+-------------+-------+-----------------------+---------------------------+------------+
| Test       | Description | Times | In work               | Used memory               | Used % CPU |
+------------+-------------+-------+-----------------------+---------------------------+------------+
| text@assoc | Assoc       | 1     | 0.0022 | 0.002238 sec | 1.078125 kb | 1.078125 kb | 0          |
+------------+-------------+-------+-----------------------+---------------------------+------------+

Bench points

To start the server, use the command:

php artisan speed:watcher

And all you have left is to put "bpoint" in the order in which you need in the code, for example in controllers:

class UserController extends Controller
{
    ...
    
    #[Get('/auth')]
    public function index(Request $request)
    {
        bpoint('Auth start');

        \Auth::loginUsingId(1, true);

        bpoint('Update user');

        \Auth::user()->touch();

        bpoint('Before return');
        
        return 'ok';
    }
    
    ...
}

And in the server console you will see:

 ---------- ----------------------------------------- 
  File       app/Http/Controllers/HomeController.php  
  Time       21:10:35.304829                          
  Message    Auth start                               
  Diff sec   0                                        
 ---------- ----------------------------------------- 

 ---------- ----------------------------------------- 
  File       app/Http/Controllers/HomeController.php  
  Time       21:10:35.310332                          
  Message    Update user                              
  Diff sec   0.0055                                   
 ---------- ----------------------------------------- 

 ---------- ----------------------------------------- 
  File       app/Http/Controllers/HomeController.php  
  Time       21:10:35.327846                          
  Message    Before return                            
  Diff sec   0.0175                                   
 ---------- ----------------------------------------- 

https://example.dev/auth

bfg/speed-test 适用场景与选型建议

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

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

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

围绕 bfg/speed-test 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-07-24