测试代码执行速度
来源:互联网 发布:淘宝店家不退款怎么办 编辑:程序博客网 时间:2024/05/02 03:11
第一种
生成实例的时候开始初始化了,在你想要测试的code后面直接调用countTime()就行,然后在你需要的地方printOut就调用result();;方便..
还可以测试总时间,把刷新的语句注释掉,就行...呵呵
PHP代码:
<?php
class TimeCount{
var $baseTime;
var $printMsg;
var $pattern;
var $printName;
function TimeCount($name){
$this->baseTime=microtime();
$this->printMsg=array();
$this->totalTime=0;
$this->pattern='^([^ ]+) (.+)';
$this->printName=$name;
}
function countTime($label){
$currentTime=microtime();
ereg($this->pattern,$currentTime,$c);
$cu=doubleval($c[2])+doubleval($c[1]);
ereg($this->pattern,$this->baseTime,$b);
$ba=doubleval($b[2])+doubleval($b[1]);
$diff=abs($cu-$ba);
$this->printMsg[]=sprintf("<br>%-20s %s s",$label,$diff);
/**
*This assignment use to refresh the baseTime ;
*When you needed to add the totalTime,Please remove the comments.
*@default remove comments;
*/
$this->baseTime=$currentTime;
}
function result(){
echo $this->printName;
foreach($this->printMsg as $v){
echo $v;
}
}
}
$timeTest=new TimeCount('Timing:');
for($i=0;$i<99999;$i++){}
$timeTest->countTime("The First Circle:");
for($i=0;$i<99999;$i++){}
$timeTest->countTime("The Second Circle:");
$timeTest->result();
?>
第二种
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((double)$usec + (double)$sec);
}
$start = getmicrotime();
//其它程序//-->
$end = getmicrotime();
$d =$end-$start;
echo "程序执行了".$d;
- 测试代码执行速度
- 用Stopwatch测试C#代码执行速度
- 测试sql执行速度
- 测试PHP代码和页面执行速度的类
- 测试优化速度代码
- sql count执行速度测试
- 优化PHP代码执行速度
- VC++代码执行速度优化
- MySQL测试SQL执行的速度测试
- PHP程序加速探索[2]--脚本执行速度测试.代码优化.压缩输出gzip
- 存储性能 - 速度测试代码
- 测试String StringBuilder StringBuffer 的执行速度
- 提高你PHP代码执行速度
- 压缩JS,提高代码执行速度
- java中代码执行速度问题
- PHP程序加速探索[4]--测试--脚本执行速度测试
- 测试项目代码执行覆盖率
- PHP程序加速探索[5]--脚本执行速度测试2
- ASP.NET编程中的十大技巧(转载)
- Apache2的httpd.conf详细翻译
- 买了个CanonA85
- 搜索的关键字变颜色
- 2005, 我走进博客堂!
- 测试代码执行速度
- 配置wap服务器
- 使用ASP加密算法加密你的数据
- 今天激活了我的blog,纪念一下!
- 在VB中实现异步调用
- microsoft office infopath 2003初探-----惊恐微软的技术垄断
- 新的一年
- 一个ListTextBox自描绘控件
- 40种网页常用小技巧(JavaScript)