audentio / timer
计时实用类
0.0.1
2022-06-03 19:32 UTC
Requires
- php: ^7.4|^8.0
This package is auto-updated.
Last update: 2024-09-30 01:43:33 UTC
README
用于计时代码执行时间和限制代码执行时间的实用类。
安装
该库应通过Composer安装。
$ composer require audentio/timer
使用方法
限制单个请求中操作的执行时间。
您可能想要限制单个请求中批量操作的执行时间,以防止超时。例如,如果您想限制为15秒,可以执行以下操作
require './vendor/autoload.php'; use Audentio\Timer\Timer; $timer = new Timer(15); while (true) { // Perform some action... if ($timer->hasExceededLimit()) { break; } }
计时操作
如果您想查看操作执行时间而不设置限制,可以执行以下操作
require './vendor/autoload.php'; use Audentio\Timer\Timer; $timer = new Timer(); sleep(15); $duration = $timer->end(); echo 'Action time in milliseconds: ' . number_format($duration->getMilliseconds());