高手赐教,linux java与c性能对比,java高呢? 本人做了个弱弱的实验,在suse linux下装了个java开发环境,写了个程序: class test{ public static void main(String[] args){ int result = 0; long start = System.currentTimeMillis();
for(int i = 0; i < 100000000; ++i){ result += i; } long end = System.currentTimeMillis(); System.out.println("runtime:"+(end - start) + "ms"); } } 运行结果:runtime:114ms c程序:
#include<sys/time.h> #include<stdio.h>
int main() { int i,result; struct timeval start,end;
result = 0; gettimeofday(&start, NULL);
for(i = 0; i < 100000000; ++i) { result += i; }
gettimeofday(&end, NULL);
printf("run time %ld ms\n",((end.tv_sec * 1000 * 1000 + end.tv_usec) -(start.tv_sec * 1000 * 1000 + start.tv_usec))/1000); } 运行结果:run time 438 ms 由此,java效率高得多呢?都说c效率比java高,测试方法错误了吗?求教