您的位置:首页 > 其它

PEAR得到程序运行时间

2005-01-27 10:56 525 查看
<?
require_once("Benchmark/Timer.php");

$String = "";
$Timer = new Benchmark_Timer();
$Timer->start();

 for($i=1;$i<=10000;$i++)
 {
   $String .= $i;
 }
$Timer->setMarker('mark1');

$String = "";
 for($i=1;$i<=1000;$i++)
 {
   $String .= $i;
 }

$Timer->stop();
$Timer->display();
?>

这样你可以清楚得看到每个程序块运行的时间,然后找到问题所在。不仅仅如此,Benchmark里另外二个类可以清楚的知道函数或者类里的方法所被CALL的次数和运行的时间。如下:

CODE
<?

require_once("Benchmark/Iterate.php");

$benchmark = new Benchmark_Iterate;

class myclass{

function foo($string) {
  for($i=1;$i<=10000;$i++)
  {
  }
}
}

$myobj = new myclass();

$benchmark->run(10, 'myobj->foo', 'test');
$result = $benchmark->get();

print_r($result);

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  string timer function class