承接 eypsilon/mycrobench 相关项目开发

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

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

eypsilon/mycrobench

最新稳定版本:v1.0.4

Composer 安装命令:

composer require eypsilon/mycrobench

包简介

MycroBench | Lightweight time measure tool for PHP

README 文档

README

This Package uses $_SERVER['REQUEST_TIME_FLOAT'] and microtime() to calculate the difference that has passed between both times, when instantiated. It also provides a basic implementation of hrtime(), which allows measuring processing times with higher precision.

See ./public/index.php for examples or check the livedemo on Vercel.

composer require eypsilon/MycroBench
use Many\MycroBench;

/**
 * @return array basic usage
 */
MycroBench::get()

// Array
// (
//     [start] => 2022-10-10 16:07:00.172129
//     [ended] => 2022-10-10 16:07:00.302257
//     [took] => 00.130128
//     [mem_usage] => 376.21 KB
//     [mem_peak] => 16.37 MB
//     [included_files_total] => 37
// )

Consecutive requests

Get the processing time that has passed between consecutive requests with internally staid start times.

The first request will use $_SERVER['REQUEST_TIME_FLOAT'] as start time, subsequent requests will use the ended time from previous requests.

Set the initial start time for benches manually to now. This is optional, but the first high resolution time will be wrong, if it's not instantiated.

/** Sets the start time for @method getBench() and @method hrBench() to now */
MycroBench::initBench()
/** @param bool true returns additional high resolution times */
MycroBench::getBench(true)

// [start] => 2022-10-10 16:07:00.176997
// [ended] => 2022-10-10 16:07:00.217398
// [took] => 00.040401
// [h_res] => 0.040415356

MycroBench::getBench(true)

// [start] => 2022-10-10 16:07:00.217398
// [ended] => 2022-10-10 16:07:00.239846
// [took] => 00.022448
// [h_res] => 0.022439554

MycroBench::getBench(true)

// [start] => 2022-10-10 16:07:00.239846
// [ended] => 2022-10-10 16:07:00.265409
// [took] => 00.025563
// [h_res] => 0.025560282

High resolution times

Get microtimes with the system's high resolution time using hrtime().

Microsec: 00.019045

High Reso: 0.019044332

// start bench
MycroBench::hrStart()

// do stuff here

// end bench, set first param true to get the result in return
MycroBench::hrEnd(false)

/** @return float|null '0.019044332' */
MycroBench::hrGet()

Get high resolution times with internally staid start times.

/** @return float|null '0.019044332' */
MycroBench::hrBench()

Misc

/**
 * microtimestamp to datetime
 *
 * @return string '2022-09-01 17:14:48.5000'
 */
(new MycroBench)->getDate('1662045288.5000') # 'U.u', 'Y-m-d H:i:s.u'

/**
 * datetime to microtimestamp
 *
 * @return string '1662045288.5000'
 */
(new MycroBench)->getDateToMicro('2022-09-01 17:14:48.5000') #'Y-m-d H:i:s.u', 'U.u'

/**
 * Get microtimestamp for the last request. Only filled
 * when @method getBench() has been called
 *
 * @return string|null '1662623500.7135'
 */
MycroBench::getLastDate()

/**
 * Readable bytes
 *
 * @return string '379.67 KB'
 */
MycroBench::readableBytes(memory_get_usage())

/**
 * Default getter
 *
 * start: $_SERVER['REQUEST_TIME_FLOAT']
 * ended: microtime(true)
 *
 * @static alias MycroBench::get()
 *
 * @param bool   enable (array) get_included_files()
 * @param string set a needle to shorten the paths returned in get_included_files()
 * @return array
 */
(new MycroBench)->getAll(true, '/remove/from/included_files/paths')

/**
 * Consecutive getter
 *
 * @static alias MycroBench::getBench()
 *
 * @param bool get additionally higher resolution times
 * @return array
 */
(new MycroBench)->getBenchDiff(true)

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固