浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
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; }
posted on 2013-03-25 16:11  lexus  阅读(288)  评论(0)    收藏  举报