calc code execeute time on c++

double get_time(){
	struct timeval t;
	gettimeofday(&t, NULL);
	double d = t.tv_sec + (double) t.tv_usec/1000000;
	return d;
}
...
double time_start = get_time();
...
double time_end = get_time();
printf("This program has run for: %f seconds.\n",  time_end - time_start);


#include<stdio.h> #include<time.h> void do_something() { for(int i=0;i<100000;i++) for(int j=0;j<10000;j++) ; } int main(int arg,char ** argv) { clock_t start=clock(); do_something(); clock_t end=clock(); float time=(float)(end-start)/CLOCKS_PER_SEC; printf("%f\n",time); return 0; }

原文链接: https://www.cnblogs.com/lexus/archive/2013/03/25/2980958.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    calc code execeute time on c++

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/81968

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 下午8:21
下一篇 2023年2月9日 下午8:21

相关推荐