10万次循环
Java代码:
double begin = System.currentTimeMillis();
for(int i=0;i<100000;i++){
System.out.println("*****"+i);
}
double end = System.currentTimeMillis();
System.out.println("循環10萬次需要的時間為:(s)"+(end-begin)/1000);
*****99998
*****99999
循環10萬次需要的時間為:(s) 1.234
*****99999
循環10萬次需要的時間為:(s) 1.234
C代码:
double begin,end;
begin = clock();
int i=0;
for(i;i<100000;i++){
//printf("%d\n",i);
printf("hello",i);
}
end = clock();
printf("循環10萬次需要的時間為:");
printf( "%f seconds\n",(end- begin)/ CLOCKS_PER_SEC);
return 0;
100万次循环
Java的时间是:
9.895(s)
C语言时间是:
反正1分钟过去了还没运行完
没测的话一直以为C什么都比Java好,可能也是Java一直在优化的原因吧
速率的话可能光从这个案例看不出来吧...