1 #include <stdio.h> 2 #include <time.h> 3 4 int main() 5 { 6 int i; 7 int k; 8 clock_t start,end; //clock_t类型实际上为long int类型(4字节) 9 printf("%d\n",sizeof(long int)); 10 start = clock(); 11 printf("start:%d\n",start); 12 for(i=0; i<10000000; i++) ; 13 end = clock(); 14 printf("end:%d\n",end); 15 printf("%.3fs\n",(double)(end-start)/CLOCKS_PER_SEC); //linux下CLOCKS_PER_SEC=1000000 16 }
运行结果:
4
start:0
end:20000
0.020s