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 ",sizeof(long int)); 10 start = clock(); 11 printf("start:%d ",start); 12 for(i=0; i<10000000; i++) ; 13 end = clock(); 14 printf("end:%d ",end); 15 printf("%.3fs ",(double)(end-start)/CLOCKS_PER_SEC); //linux下CLOCKS_PER_SEC=1000000 16 }
运行结果:
4
start:0
end:20000
0.020s