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

测试程序运行时间

级别: 终身会员
发帖
3743
铜板
8
人品值
493
贡献值
9
交易币
0
好评度
3746
信誉值
0
金币
0
所在楼道
ACM题目大都有规定运行时间的, G_;)a]v8)  
!\nBh  
那么我们如何测得程序运行时间呢? |^:cG4e  
B~]k#Ot)  
这就得益于C++函数库time.h Aydm2!l1  
xSktg]u Se  
下面是一段示范代码: e- :yb^  
7S '% E  
#include<iostream> R)_%i<nq\  
#include<time.h> t[ubn+  
using namespace std; QS%%^+E2  
int main() nygbt<;?  
{  aC$B2  
    long beginTime =clock();//获得开始时间,单位为毫秒 aZ2!i  
]NUl9t*N4  
    for(int i=0;i<10000;i++){cout<<i<<endl;}//输出10000行数字 JlH&??  
K(q+ "  
    long endTime=clock();//获得结束时间 .>= (' -  
<e Th  
    cout<<"beginTime:"<<beginTime<<endl +c(zo4nZ  
        <<"endTime:"<<endTime<<endl ^T*?>%`  
        <<"endTime-beginTime:"<<endTime-beginTime<<endl; ![`Ay4AZ@a  
vI:;A/&  
    return 0; jr)1(**  
}
评价一下你浏览此帖子的感受

精彩

感动

搞笑

开心

愤怒

无聊

灌水
级别: 终身会员
发帖
3743
铜板
8
人品值
493
贡献值
9
交易币
0
好评度
3746
信誉值
0
金币
0
所在楼道
只看该作者 2 发表于: 2006-06-12
呵呵~~~
级别: 经院高中
发帖
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. %>
Cj{1H([-  
0:9.;x9_  
擅长脚本,ASP写一个 cc~O&?)i  
PHP再一个。 Qa-K$dm%  
sj HrPs e  
  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. ?>
3HcQ(+Z  
nlW +.a[  
7ccO93Mz  
转的~~~
描述
快速回复

您目前还是游客,请 登录注册
欢迎提供真实交流,考虑发帖者的感受
认证码:
验证问题:
3+5=?,请输入中文答案:八 正确答案:八