列出每一标记的时间索引,与上一标记之间的运行时间,与上一标记之间的运行时间占总耗时的百分比,以及总耗时.
调用该方法前,应该先调用stop()来终止计时(并不会终止程序).见例2.
方法: getoutput( )
描述:返回格式化后的计时器信息. 该方法把计时器信息放如一个表中(如上表),供display()方法列出.
方法:getprofiling( )
描述:返回计时器信息.将是形如array
(
[0] => array
(
[name] => start
[time] => 1099021787.69669100
[diff] => -
[total] => 1099021787.696691
)
[1] => array
(
[name] => mark1
[time] => 1099021787.69675900
[diff] => 0.000068
[total] => 1099021787.696759
)
[2] => array
(
[name] => mark2
[time] => 1099021787.69683500
[diff] => 0.000076
[total] => 1099021787.696835
)
[3] => array
(
[name] => stop
[time] => 1099021787.69694500
[diff] => 0.000110
[total] => 1099021787.696945
)
)
的二维数组.0,1,2...为标记所在位置.假设x为某一标记所在位置,则$profiling[x]['name'] = 标记x的名称 $profiling[x]['time'] = 标记x的时间索引 $profiling[x]['diff'] = 从x-1标记到x标记之间运行的时间差 $profiling[x]['total'] = 在标记x以前所有的运行时间.
方法:setmarker( string $name)
描述:设置标记.
参数:string $name - 欲设置的标记的名称,且区分大小写.
方法:start( )
描述:设置"开始(start)"标记,也代表着计时的开始.
方法:stop( )
描述:设置"终止(stop)"标记,也代表着计时的终止.
方法:double timeelapsed( [string $start = 'start'], [string $end = 'stop'])
描述:返回两个标记之间的耗时.
参数:
string $start - 开始标记,缺省为"start"
string $end - 结束标记,缺省为"stop"
含6位小数.
应用
1,记录两点的时间差//创建一个对象
$timer = new benchmark_timer();
//设置标记 ("mark1")
$timer->setmarker("mark1");
//一段测试
for ($i=0; $i<100; $i++)
{
//we do nothing here
}
$timer->setmarker("mark2");
//输出两点之间的用时
echo $timer->timeelapsed("mark1", "mark2");
2,列出计时器的信息.//创建一个对象
$timer = new benchmark_timer();
//计时开始
$timer->start();
$timer->setmarker("mark1");
//一段测试
for ($i=0; $i<100; $i++)
{
//we do nothing here
}
$timer->setmarker("mark2");
//输出两点之间的用时