社区应用 最新帖子 精华区 社区服务 会员列表 统计排行 社区论坛任务 迷你宠物
  • 2581阅读
  • 2回复

测试程序运行时间

级别: 终身会员
发帖
3743
铜板
8
人品值
493
贡献值
9
交易币
0
好评度
3746
信誉值
0
金币
0
所在楼道
ACM题目大都有规定运行时间的, j2z$kw%  
<NUZPX29  
那么我们如何测得程序运行时间呢? Z7 @#0;g{  
{VFp fo  
这就得益于C++函数库time.h #Xc~3rg9  
}v:h EMO  
下面是一段示范代码: uBM1;9h  
wG B'c's*  
#include<iostream> WrV|<%EQh  
#include<time.h> )S]c'}^  
using namespace std; XH/|jE.9^|  
int main() tC;D4i  
{ |D\ ukml  
    long beginTime =clock();//获得开始时间,单位为毫秒 ,?}TSJKC  
:c\NBKHv*  
    for(int i=0;i<10000;i++){cout<<i<<endl;}//输出10000行数字 !j(R _wOq  
=<<\Uo  
    long endTime=clock();//获得结束时间 7M4iBk4I  
P++gR@  
    cout<<"beginTime:"<<beginTime<<endl a P`;Nr=  
        <<"endTime:"<<endTime<<endl !U91  
        <<"endTime-beginTime:"<<endTime-beginTime<<endl; OSBE5  
Y{jhT^tKK  
    return 0; N.fIg  
}
评价一下你浏览此帖子的感受

精彩

感动

搞笑

开心

愤怒

无聊

灌水
级别: 经院高中
发帖
369
铜板
3800
人品值
215
贡献值
0
交易币
0
好评度
305
信誉值
0
金币
0
所在楼道
只看该作者 1 发表于: 2006-06-12
  1. <%
  2. dim t1,t2
  3. t1=now()
  4. ' your asp code place here
  5. ' .......
  6. t2=now()
  7. response.write "执行用了"&cstr(cdbl((t2-t1)*24*60*60)) & "秒 "
  8. %>
4 ))ZBq?  
9lqH  
擅长脚本,ASP写一个 $Y`oqw?g+^  
PHP再一个。 JCO+_d#x  
Gu@n1/m@o  
  1. <?php
  2. function getmicrotime(){
  3. list($usec, $sec) = explode(" ",microtime());
  4. return ((float)$usec + (float)$sec);
  5. }
  6. //例子
  7. //开始
  8. $time_start = getmicrotime();
  9. //这里放你的代码
  10. //结束
  11. $time_end = getmicrotime();
  12. $time = $time_end - $time_start;
  13. echo "Did nothing in $time seconds"; //输出运行总时间
  14. ?>
}ff+RGxLIG  
X)Zc*9XA  
h>k[  
转的~~~
级别: 终身会员
发帖
3743
铜板
8
人品值
493
贡献值
9
交易币
0
好评度
3746
信誉值
0
金币
0
所在楼道
只看该作者 2 发表于: 2006-06-12
呵呵~~~
描述
快速回复

您目前还是游客,请 登录注册
批量上传需要先选择文件,再选择上传
认证码:
验证问题:
10+5=?,请输入中文答案:十五