定制 drealecs/time-benchmark 二次开发

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

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

drealecs/time-benchmark

最新稳定版本:v1.1.1

Composer 安装命令:

composer require drealecs/time-benchmark

包简介

Library for timing execution and benchmarking

README 文档

README

Library for timing execution and benchmarking

Stopwatch

An instance of the stopwatch can be created with the static methods:

$stopwatch = Stopwatch::create();

or

$stopwatch = Stopwatch::createStarted();

As the name suggests createStarted() method is also starting the stopwatch. A not started stopwatch can be started using

$stopwatch->start();

When a stopwatch is started, it can be stopped with

$stopwatch->stop();

While capturing time, hrtime() is used for the best efficiency. On 32-bit runtimes there might be some decimal losses due to float php precision limit but only on microsecond decimals level. The methods start() and stop() are fast and the calculation of the difference is done when calling the methods:

$seconds = $stopwatch->getElapsedSeconds();
$milliseconds = $stopwatch->getElapsedMilliseconds();
$microseconds = $stopwatch->getElapsedMicroseconds();

There are also three stopwatch status methods that can be used

$stopwatch->wasStarted();
$stopwatch->isRunning();
$stopwatch->wasStopped();

Another functionality also included is related to steps (or laps). When a stopwatch is running, steps can be marked without affecting the stopwatch status with:

$stopwatch->step($stepName);

$stepName is the name of the step and must not be reused for the same stopwatch.

The number of steps can be retrieved with

$stopwatch->getStepsNumber();

There are three methods for retrieving the time difference between start and each of the steps. The result is an array indexed by the step name.

$seconds = $stopwatch->getElapsedStepsSeconds();
$milliseconds = $stopwatch->getElapsedStepsMilliseconds();
$microseconds = $stopwatch->getElapsedStepsMicroseconds();

There is support for pausing the stopwatch. The methods to do this are:

$stopwatch->pause();
$stopwatch->resume();

Pausing and resuming are as fast as possible, and the calculation is done within the getElapsed* methods.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-05-24