都说c执行速度比java快,但我的测试确相反,是java执行速度提高了???
测试环境如下:
[lyb@lyb-centos5 Desktop]$ uname -a
Linux lyb-centos5 2.6.18-92.1.6.el5 #1 SMP Wed Jun 25 13:49:24 EDT 2008 i686 i686 i386 GNU/Linux
[lyb@lyb-centos5 Desktop]$ java -version
java version "1.6.0_06"
Java(TM) SE Runtime Environment (build 1.6.0_06-b02)
Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode, sharing)
[lyb@lyb-centos5 Desktop]$ cc --version
cc (GCC) 4.1.2 20071124 (Red Hat 4.1.2-42)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
测试程序C:
cT.c
#include
#include
int main ()
{
int i;
int j=9;
for(i=1000000000;i>0;i--)
{
j=i;
}
printf("value %d",j);
}
测试程序JAVA:
jT.java
public class jT{
public static void main(String [] args){
int i;
int j=9;
for(i=1000000000;i>0;i--){
j=i;
}
System.out.println("value "+j);
}
}
编译与执行:
[lyb@lyb-centos5 Desktop]$ cc -o cT cT.c
[lyb@lyb-centos5 Desktop]$ javac jT.java
[lyb@lyb-centos5 Desktop]$ time cT
value 1
real 0m4.738s
user 0m4.341s
sys 0m0.030s
[lyb@lyb-centos5 Desktop]$ time java jT
value 1
real 0m3.451s
user 0m3.242s
sys 0m0.040s
[lyb@lyb-centos5 Desktop]$ time cT
value 1
real 0m6.908s
user 0m6.532s
sys 0m0.056s
[lyb@lyb-centos5 Desktop]$ time java jT
value 1
real 0m3.361s
user 0m3.159s
sys 0m0.041s
[lyb@lyb-centos5 Desktop]$ time java jT
value 1
real 0m3.346s
user 0m3.154s
sys 0m0.041s
[lyb@lyb-centos5 Desktop]$ time cT
value 1
real 0m6.995s
user 0m6.672s
sys 0m0.067s
[lyb@lyb-centos5 Desktop]$ time java -server jT
value 1
real 0m0.862s
user 0m0.342s
sys 0m0.044s
[lyb@lyb-centos5 Desktop]$ time java -server jT
value 1
real 0m0.273s
user 0m0.176s
sys 0m0.021s
结果:
从上面的执行情况看,java明显胜出,如果java打开-server选项,速度更是有质的提升,
阅读(1638) | 评论(1) | 转发(1) |