Class M_time
<?php
class timer
{
var $costs = array();
var $msg = array();
var $print = 1;
function timer($print=1)
{
$this->costs[] = $this->getmicrotime();
$this->msg[] = "start";
$this->print=$print;
if($print)
{
echo "start:\t".$this->costs[0]."<br>\n";
}
}
function b($msg='')
{
$prev = end($this->costs);
$end = $this->getmicrotime();
$this->costs[] = $end;
$this->msg[] = $msg;
if($this->print)
{
echo $msg.": \t".($end-$prev)."<br>\n";
}
}
function p()
{
$n=count($this->costs);
for ($i=1;$i<$n ;$i++ )
{
$cost = round( ($this->costs[$i] - $this->costs[$i-1] ) , 6 ) ;
$msg = $this->msg[$i];
echo $cost . "\t" . $msg . "<br>\n";
}
$start = array_shift($this->costs);
$end = end($this->costs);
echo "共计耗费: ".round( ($end-$start) , 6 ) . "秒";
}
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
}
/*
$t = new timer(1);
$t->b( "FT" );
*/
?>
本文链接: http://base5.cn/index.php/archives/104