wizzaro/execution-code-timer

该库提供了一种简单的方式来测量代码的执行时间

1.0.0 2019-01-16 15:19 UTC

This package is not auto-updated.

Last update: 2024-09-20 19:45:28 UTC


README

该库提供了一种简单的方式来测量代码的执行时间

示例用法

$timer = new Wizzaro\ExecutionCodeTimer\Timer(true);
sleep(2);
echo $timer->getExecutionInfo();

API

构造函数

public Timer::__construct(bool $startMeasurement = false)

参数

  • startMeasurement - 在创建对象时开始测量

startMeasurement

开始测量

public function startMeasurement(): void

异常

  • 如果尝试再次开始测量,则抛出 Exception

hasMeasurementWasStarted

检查测量是否已经开始

public function hasMeasurementWasStarted(): bool

getExecutionInfo

public function getExecutionInfo(string $format = ''): string

参数

返回

  • 根据格式返回代码执行时间的信息

setExecutionInfoFormat

设置代码执行时间信息的默认格式

public function setExecutionInfoFormat(string $format): void

参数

getExecutionInfoFormat

public function getExecutionInfoFormat(): string

返回

  • 返回代码执行时间信息的默认格式

getExecutionTime

public function getExecutionTime(): DateInterval

返回

  • 返回开始测量时间与当前时间之间的间隔

getStartTime

public function getStartTime(): DateTimeInterface

返回

  • 返回开始测量时间

异常

  • 如果测量尚未开始,则抛出 Exception

getCurrentTime

public function getCurrentTime(): DateTimeInterface

返回

  • 基于 microtime 返回当前时间

运行测试

要运行测试

  1. 克隆仓库
$ git clone https://github.com/Wizzaro/execution-code-timer.git
$ cd execution-code-timer
  1. 使用 composer 安装依赖项
$ composer install

如果您尚未安装 composer,请从 https://getcomposer.org/download/ 下载

  1. 使用 composer.json 中提供的 "test" 命令运行测试
$ composer test

您可以使用 phpunit.xml 文件开启条件测试。为此

phpunit.xml.dist 文件复制到 phpunit.xml,编辑 phpunit.xml 以启用您想测试的任何特定功能,并提供用于利用的测试值。