raitocz / timer
简单的计时器。这是一个针对PHP 5.3的旧项目工作的weew/timer的分支。
1.0.5
2017-10-12 13:25 UTC
Requires
- weew/helpers-array-legacy: ^1.0.0
Requires (Dev)
- phpunit/phpunit: ^4.7
- satooshi/php-coveralls: ^0.6.1
README
目录
安装
composer require raitocz/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');