mmdm/sim-benchmark 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mmdm/sim-benchmark

Composer 安装命令:

composer require mmdm/sim-benchmark

包简介

A simple yet nice benchmark for your codes

README 文档

README

A library to benchmark codes time elapsed and memory usage.

Install

composer

composer require mmdm/sim-benchmark

Or you can simply download zip file from github and extract it, then put file to your project library and use it like other libraries.

Just add line below to autoload files:

require_once 'path_to_library/autoloader.php';

and you are good to go.

How to use

// to instance a benchamrk object
$benchmark = new Benchmark();
$label = 'a label';

// start benchmark here
$benchmark->start($label);
// here you should write your algorithm
// ...
// now you can stop benchmark
$benchmark->stop($label);

//now you can see result like this
$benchmark->getReport($label);

Available functions

start($label):

This method starts a benchmark for a specific label.

Note: This method just work one time for a specific label.

$benchmark->start($label);

pause($label):

This method pause a benchmark for a specific label.

Note: If you use this method multiple times before resume method, first call will apply.

$benchmark->pause($label);

resume($label):

This method resume a benchmark for a specific label.

Note: If you use this method multiple times before pause method, first call will apply.

$benchmark->resume($label);

stop($label):

This method stop a benchmark for a specific label.

Note: This method just work one time for a specific label.

$benchmark->stop($label);

getTime($label):

This method get time for a specific label.

Note: Use this function before start and stop methods, will cause exception.

Note: Returns time as microseconds in float format

$time = $benchmark->getTime($label);

getMemory($label):

This method get memory for a specific label.

Note: Use this function before start and stop methods, will cause exception.

Note: Returns memory as bytes in int format

$memory = $benchmark->getMemory($label);

get($label):

This method get time and memory for a specific label.

Note: Use this function before start and stop methods, will cause exception.

Note: Returns an array like below format

array [
    'time' => $time, // 2 microsecond(s), etc.
    'memory' => $memory // 10MiB, etc.
]
$res = $benchmark->get($label);

getReport($label):

This method show a report of a specific label.

Note: Use this function before start and stop methods, will cause exception.

Note: This method is void

$benchmark->getReport($label);

License

Under MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-07-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固