天天看点

记录程序运行时间的程序实例

记录一个程序所用时间,另外在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 }