<span style="font-size:18px;"><strong> int main() { int number=0,i=0; for(i=0;i<=1000000000;i++) number++; return 0; }</strong></span>C语言的编译器是gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2。编译的程序a.out的运行时间用time测出,为real 0m3.153s, user 0m3.152s, sys 0m0.000s
<span style="font-size:18px;"><strong> public class tst { public static void main(String[] args) { int i; int number=0; long startTime = System.currentTimeMillis();//运行起止时间 for(i=0;i<=1000000000;i++) number++; long endTime = System.currentTimeMillis();//运行终止时间 float seconds = (endTime - startTime)/1000F; System.out.println(Float.toString(seconds) + " seconds."); } }</strong></span>java的编译器是javac 1.7.0_79,java虚拟机是java version "1.7.0_79",OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu0.14.04.2),OpenJDK Server VM (build 24.79-b02, mixed mode)。time测出的结果为:real 0m0.093s,user 0m0.088s,sys 0m0.008s(注:如果用java的函数测试的话(不考虑jvm的时间开销)运行时间为0.006 seconds.)
原文地址:http://blog.csdn.net/biosman/article/details/46406547