mvan/stopwatch

用于测量脚本运行时间的计时器

v1.1 2021-04-16 13:40 UTC

This package is auto-updated.

Last update: 2024-09-16 21:17:05 UTC


README

StopWatch - 在脚本内部测量时间

这个库是一个超简单的工具,用于测量脚本中两点之间的时间。

配置

将库添加到您的项目中的 composer.json 文件

{
  "require": {
      "mvan/stopwatch": "1.*"
  }
}

使用 composer 安装库

$ php composer.phar install

Composer 会将 CLItoris 安装在您的 vendor 文件夹中。然后,您可以在 .php 文件中添加以下内容以使用库进行自动加载。

require_once __DIR__ . '/vendor/autoload.php';

或者,在命令行中使用 composer 来要求并安装 CLItoris

$ php composer.phar require mvan/stopwatch:1.*

最低要求

  • PHP 7

使用方法

<?php

$sw = new StopWatch();
// Set a start point in time
$sw->start();
sleep(30);
// Stop measuring time
$sw->stop();

// Show results
print $sw->getResult().PHP_EOL;
print $sw->getResult(StopWatch::IN_SECONDS).PHP_EOL;
print $sw->getResult(StopWatch::IN_MINUTES).PHP_EOL;