记录一个程序所用时间,另外在linux服务器上提交东西的指令
yhrun -p TH_NEW ./a.out >
1 #include <cstdio>
2 #include <ctime>
3 #include <cstdlib>
4 #include <sys/time.h>
5 #include <time.h>
6 struct node {
7 int a[3];
8 };
9 node ans [16][3920][18000];
10 int main()
11 {
12 printf("start!\n");
13 int a;
14 srand(0);
15 struct timeval tv_start,tv_end;
16 gettimeofday(&tv_start,NULL);
17 //程序
27 gettimeofday(&tv_end,NULL);
28 printf("time: %lf\n",tv_end.tv_sec - tv_start.tv_sec+(tv_end.tv_usec - tv_start.tv_ usec)/1000000.0);
29 return 0;
30 }

本文介绍了一个使用C++进行程序运行时间测量的方法。通过`sys/time.h`库中的`gettimeofday`函数,实现了精确到微秒级别的计时,并展示了如何在程序开始和结束时记录时间戳来计算总的运行时间。
6270

被折叠的 条评论
为什么被折叠?



