jopmesman/logtimer

此包最新版本(1.0.3)没有提供许可证信息。

简单的计时器。

1.0.3 2019-08-29 18:31 UTC

This package is not auto-updated.

Last update: 2024-09-20 20:37:14 UTC


README

这个非常简单的包可以用来在php中对过程进行计时。

安装

composer require jopmesman/logtimer

要使用计时器

在您想要计时的过程之前。

LogTimer::time('Any text');

在您想要计时的过程之后,添加相同的行。

LogTimer::time('Any text');

此时,这两行之间的时间将被计时。在完整的脚本结束时,您可以得到所有计时项目。

print_r(LogTimer::times());

这将得到以下结果

Array 
(
  "Any text" => 2.0019979476929
)

以下是一个完整示例

LogTimer::time('Complete process');
LogTimer::time('Get all rows from the database');
$data = getAllDataFromDB();
LogTimer::time('Get all rows from the database');
//Loop over all the rows from the database
LogTimer::time('Looping');
$return = [];
foreach ($data as $row) {
    $return[$row['id']] = $row['name'];
}
LogTimer::time('Looping');
LogTimer::time('Complete process');

print_r(LogTimer::times());

print_r的结果可能如下所示

Array
(
    [Get all rows from the database] => 1.0011401176453
    [Looping] => 2.0006589889526
    [Complete process] => 3.0018129348755
)