用到了程序的运行效率, 写了个计算时间的方法,
但是加上sleep(1)后,不起作用,不知道为什么
但是可以起到计算时间的作用;
另外time ./a.out 也可以计算时间
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <time.h>
47 //#include <dos.h>
48
49 int main(int argc, char *argv[])
50 {
51 double count = 0;
52 clock_t start, end;
53 start = clock();
54 printf("aaaaaaaaaaa %ld\n", (long int)start);
55 // sleep(1);
56 long int i = 10000000;;
57 while(i>0)
58 i--;
59 end = clock();
60 printf("bbbbbbbbbb:%ld\n", (long int)end);
61 printf("CLOCKS_PRE_SEC %ld \n", CLOCKS_PER_SEC);
62 count = (double)(end - start) * 1000/((double)CLOCKS_PER_SEC);
63 printf("The time was: %f min sec\n", count );//(double)(end - start)/(double)CLOCKS_PER_SEC);// / CLK_TCK);
64 return 0;
65 }
./a.out
aaaaaaaaaaa 0
bbbbbbbbbb:20000
CLOCKS_PRE_SEC 1000000
The time was: 20.000000 min sec
time ./a.out
aaaaaaaaaaa 0
bbbbbbbbbb:20000
CLOCKS_PRE_SEC 1000000
The time was: 20.000000 min sec
real 0m0.054s
user 0m0.028s
sys 0m0.000s