zwynch/timer

简单计时器。这是基于weew/timer的一个分支,适用于PHP 5.3的老旧项目。

v1.0.1 2023-01-10 10:55 UTC

This package is not auto-updated.

Last update: 2024-10-02 18:42:46 UTC


README

Build Status Test Coverage Dependencies Version Licence

目录

安装

composer require zwynch/timer

介绍

这个非常简单的库可以用来衡量你代码的执行时间,或者当你需要秒表时使用。

基本用法

你可以获取计时器开始和停止之间的持续时间。

$timer = new Timer();
$timer->start();
sleep(1);
$timer->stop();
echo $timer->getDuration(); // 1.0234

检查点

你可以随时创建自定义检查点,并检索达到检查点所经过的时间。

$timer = new Timer();
$timer->start();
$timer->createCheckpoint('foo');
$timer->stop();

$timer->getStartTime(); // returns start time in microseconds
$timer->getStopTime(); // returns stop time

$timer->getCheckpoint('start'); // returns start time
$timer->getCheckpoint('stop'); // returns stop time
$timer->getCheckpoint('foo'); // returns time of the checkpoint foo

检查点之间的持续时间

你可以测量检查点之间的持续时间。

$timer = new Timer();
$timer->createCheckpoint('foo');
sleep(1);
$timer->createCheckpoint('bar');

// returns time elapsed since checkpoint foo till now
$timer->getDuration('foo');
// returns duration between checkpoints foo and bar
$timer->getDuration('foo', 'bar');

$timer->stop();
// returns time between checkpoints foo and stop
$timer->getDuration('foo');