geekality/timer

此包已被弃用,不再维护。未建议替代包。

用于记录时间和内存使用的简单类

v1.2 2013-05-15 06:29 UTC

This package is not auto-updated.

Last update: 2021-05-14 21:54:14 UTC


README

用于记录方法和此类的时间及内存使用的简单类。

Timer::__toString()方法将创建一个简单的纯文本概述,但您当然也可以通过直接使用Timer对象属性来创建自己的输出。

安装

如果您使用我强烈推荐的Composer,只需在您的composer.json中添加以下依赖项

    "require":
    {
    	"geekality/timer": "1.*"
	},

否则,只需从这里下载Timer.php文件,并将其包含到您的项目中。它是自包含的,所以您只需要这一个文件。

示例用法

Timer::start('root');
// Stuff
Timer::start('section');
// Sub section stuff
Timer::stop();
// More stuff
echo Timer::result();

以下是从该仓库中的sample/add.php脚本中的部分示例输出。

/TimerPHP/sample/add.php(3, 9)
 │ 
 │ 7.001 s
 │ 4.02 KiB, 732.41 KiB
 │ 
 ├ SlowMath::slowAdd(3, 9)
 │  │ 
 │  │ 4.001 s
 │  │ 432.00 B, 732.41 KiB
 │ ─┘ 
 │ 
 ├ test(null, true, false)
 │  │ 
 │  │ 2.000 s
 │  │ 176.00 B, 732.41 KiB
 │ ─┘ 

如果您想看到这个类的更多使用,可以查看我的项目Svish/MyHymnal。在那里,我也将结果输出到文件中,您可以通过点击网站右下角的微型调试链接来加载该文件。

许可证

本作品根据Creative Commons Attribution 3.0 Unported License许可。要查看此许可证的副本,请访问Creative Commons Attribution 3.0 Unported License

Creative Commons License