weew/timer

简单的计时器。

v1.0.1 2016-07-21 11:18 UTC

This package is not auto-updated.

Last update: 2024-09-10 22:31:33 UTC


README

Build Status Code Quality Test Coverage Dependencies Version Licence

目录

安装

composer require weew/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');