定制 ggomuk/g-bench 二次开发

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

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

ggomuk/g-bench

Composer 安装命令:

composer require ggomuk/g-bench

包简介

PHP Benchmark Component

README 文档

README

G-Bench is a nice and light component for php benchmarking.

Installation

Add this in your composer.json

{
    "require": {
        "ggomuk/g-bench": "1.0.0"
    }
}

Sample Usage

  • start(), stop()

    require_once __DIR__ . '/vendor/autoload.php';
    
    $gb = new \GBench\GBench();
    
    $gb->start();
    $temp = str_repeat('Hello World!', 10000);
    sleep(2);
    $gb->stop();
    
    $gb->getDuration(); // 2003 (ms)
    $gb->getMemory(); // 2097152 (bytes)
    
    echo $gb; // 2.00 MB - 2003 ms
  • record()

    require_once __DIR__ . '/vendor/autoload.php';
    
    $gb = new \GBench\GBench();
    
    $gb->start();
    
    usleep(500000);
    $temp1 = str_repeat('Hello World!', 10000);
    
    // You can label records with the record method.
    // The benchmark does not stop as it only makes an intermediate record.
    $gb->record('step1');
    
    usleep(500000);
    $temp2 = str_repeat('Hello World!', 100000);
    
    // You can also label records with the stop method.
    $gb->stop('step2');
    
    // The details of the record can be seen below
    foreach ($gb->getRecords() as $record) {
        $record->getLabel(); // step1, step2
        $record->getMemory(); // 2097152, 2097152
        $record->getDuration(); // 505, 506
        $record->getAccumulateMemory(); // 2097152, 4194304
    
        echo $record;
        // Usage Memory : 2.00 MB | Accumulate Usage Memory : 2.00 MB | Record Duration : 505 ms -> step1
        // Usage Memory : 2.00 MB | Accumulate Usage Memory : 4.00 MB | Record Duration : 506 ms -> step2
    }
  • run()

    require_once __DIR__ . '/vendor/autoload.php';
    
    $gb = new \GBench\GBench();
    $result = $gb->run(function () {
        usleep(500000);
        return str_repeat('Hello World!', 10000);
    }, 'sample_run');
    
    $gb->getDuration() . "\n"; // 504 (ms)
    $gb->getMemory() . "\n"; // 2097152 (bytes)
    echo $gb . "\n"; // 2.00 MB - 504 ms
  • Handler

    require_once __DIR__ . '/vendor/autoload.php';
    
    $logger = new class extends \GBench\AbstractHandler {
        public function startAfter(\GBench\GBench $gbench)
        {
            echo 'good start';
        }
    
        public function stopAfter(\GBench\GBench $gbench, \GBench\Record $record)
        {
            echo 'good stop';
        }
    };
    
    $gb = new \GBench\GBench($logger);
    $gb->start(); // good start
    $gb->stop(); // good stop

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-02-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固