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的次数和运行的时间。如下:
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); ?> |
相关文章推荐
- php 计算程序运行时间的类,以及用它和Curl结合Host,实现不用配置Host得到该测试机的访问速度。
- C语言linux环境下使用gettimeofday函数得到程序运行时间
- vc++ 如何得到程序运行时间
- 如何在VC6.0中得到一个程序的运行时间,也就是这个程序耗费的时钟周期数// C和C++的时间编程
- 怎样得到程序的运行路径,以系统时间命名文件
- php 计算程序运行时间的类,以及用它和Curl结合Host,实现不用配置Host得到该测试机的访问速度。
- 紧急求助国内外大侠:如何编写程序得到正在运行的ppt的当前页码和运行时间?
- C++可以用的计算程序运行时间的方法
- C程序运行时间计算
- 第十四周项目—阅读并运行程序,解释程序执行得到的结果(2)
- 1026. 程序运行时间(15)
- 程序运行时间(15)
- 1026. 程序运行时间(15)
- 第十四周项目一(2) 阅读程序,解释程序运行得到的结果
- 1026. 程序运行时间
- 使用System.Diagnostics.Stopwatch对程序的运行时间精确地测量
- C语言如何 计算程序运行时间?
- 计算程序运行时间
- C#中提供的精准测试程序运行时间的类Stopwatch
- 在dos下运行程序并得到运行结果