Topic: Java 比 C++更快???

  Print this page

1.Java 比 C++更快??? Copy to clipboard
Posted by: lifangning
Posted on: 2004-06-17 07:46

程序员一直认为,由于JVM的关系,Java的执行效率低于C/C++……
但从最近的一则测试表明,Java和C++有得一拼:

http://www.sys-con.com/story/?storyid=45250

2.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: floater
Posted on: 2004-06-17 09:43

good, glad to know this.

3.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: jigsaw
Posted on: 2004-06-17 09:48

这类测试统统很无聊。。。

4.Re:Java 比 C++更快??? [Re: jigsaw] Copy to clipboard
Posted by: aryuan
Posted on: 2004-06-17 12:25

快不快重要的是在使用的时候的一种感觉,

没人会在意这些数字的。
现实一点吧

5.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: julysea
Posted on: 2004-06-18 13:53

顶,同意楼上的意见,关键在实际的应用,什么合适就用什么,不单纯是运行速度的事

6.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: hexianmao
Posted on: 2004-06-18 15:15

支持,至少从根本上说明。JAVA还是牛的。

7.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: qgjtso
Posted on: 2004-06-18 22:39

java 比C++至少慢动作1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

8.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: xidianliuy
Posted on: 2004-06-18 23:31

给我的感觉,在java程序第一次运行时怎么也没有C++快,但当运行同样一个程序10000次时,平均时间还是很快!!!

9.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: lalphbet
Posted on: 2004-06-19 17:13

学过编译原理没有?
如果没有,去学一学吧~

10.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: stlinuxily
Posted on: 2004-06-19 18:50

编译...有原理吗?

11.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: cchuier
Posted on: 2004-06-19 20:08

何必呢?发这个帖子还不是心虚
c++现在还是比java快的,事实就是事实
无论你怎么说

12.Re:Java 比 C++更快??? [Re: lalphbet] Copy to clipboard
Posted by: lifangning
Posted on: 2004-06-20 12:34

呵呵,学过编译原理的大哥好牛~~~~
Java在虚拟机上运行,但运行C++的操作系统本身也就是一个虚拟机呀~~
仅靠一些纯理论的纸上谈兵谁不会呀?
有本事去研究研究人家的测试代码,看看人家的测试代码有什么问题,为什么会得到这样的测试结果~~~~~

13.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: floater
Posted on: 2004-06-21 05:49

lifangning wrote:
仅靠一些纯理论的纸上谈兵谁不会呀?
有本事去研究研究人家的测试代码,看看人家的测试代码有什么问题,为什么会得到这样的测试结果~~~~~

good point!

14.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: samuelxp
Posted on: 2004-06-21 09:56

Don't pay so much attention to languages.

15.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: scottding
Posted on: 2004-06-21 16:08

希望大家不要再争论这个无聊的问题了,单就某一个方面根本不具备可比性,无聊的去比较Java和C++那个快,有意义么?Java和C++专注的方面就不同。去比了干什么?做多了这样无聊的比较反而会对一些初学者产生误导,要知道,“快”并不是选择语言的唯一指标!

16.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: Jakie
Posted on: 2004-06-21 17:09

同条件下win xp 比 98慢, 但还是有人用,
你的 386 下的win95 就 比p4 下的win xp 快吗?

有必要争论吗?!

17.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: nsd
Posted on: 2004-06-22 11:06

Gosling确实这么说过,在某些情况下java的执行速度要超过c++,我当时还以为听错了呢。不过起码能说明这种说法不是空穴来风,无稽之谈什么的。
c和c++,同样是本地代码,但是c程序员就对c++的效率嗤之以鼻。所以不要觉得本地代码都是多么的快。起码我觉得java虚拟机提供的内存管理相对于本地代码来说就是一个很大的优势,没有这个机制的话很难保证很多应用系统的稳固运行。

18.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: guru
Posted on: 2004-06-22 13:23

俺怀疑他的测试结果,我自己做了一个实验,即其中的费波纳切数列的那个例子,结果如下:

Java:

  Command being timed: "java -classpath . fibo 45"
  User time (seconds): 0.01
  System time (seconds): 0.01
  Percent of CPU this job got: 0%
  Elapsed (wall clock) time (h:mm:ss or m:ss): 0:39.79
  Average shared text size (kbytes): 0
  Average unshared data size (kbytes): 0
  Average stack size (kbytes): 0
  Average total size (kbytes): 0
  Maximum resident set size (kbytes): 7680
  Average resident set size (kbytes): 0
  Major (requiring I/O) page faults: 499
  Minor (reclaiming a frame) page faults: 0
  Voluntary context switches: 0
  Involuntary context switches: 0
  Swaps: 0
  File system inputs: 0
  File system outputs: 0
  Socket messages sent: 0
  Socket messages received: 0
  Signals delivered: 0
  Page size (bytes): 4096
  Exit status: 0

CPP:
  Command being timed: "fibo 45"
  User time (seconds): 31.23
  System time (seconds): 0.04
  Percent of CPU this job got: 99%
  Elapsed (wall clock) time (h:mm:ss or m:ss): 0:31.46
  Average shared text size (kbytes): 0
  Average unshared data size (kbytes): 0
  Average stack size (kbytes): 0
  Average total size (kbytes): 0
  Maximum resident set size (kbytes): 13536
  Average resident set size (kbytes): 0
  Major (requiring I/O) page faults: 850
  Minor (reclaiming a frame) page faults: 0
  Voluntary context switches: 0
  Involuntary context switches: 0
  Swaps: 0
  File system inputs: 0
  File system outputs: 0
  Socket messages sent: 0
  Socket messages received: 0
  Signals delivered: 0
  Page size (bytes): 4096
  Exit status: 0

多次测试的结果与此上述结果类似,都是CPP快于Java。

19.Re:Java 比 C++更快??? [Re: nsd] Copy to clipboard
Posted by: samuelxp
Posted on: 2004-06-23 09:39

nsd wrote:
...起码我觉得java虚拟机提供的内存管理相对于本地代码来说就是一个很大的优势,没有这个机制的话很难保证很多应用系统的稳固运行。


对于你这句话非常之不赞同。

20.Re:Java 比 C++更快??? [Re: stlinuxily] Copy to clipboard
Posted by: kam
Posted on: 2004-06-23 10:34

stlinuxily wrote:
编译...有原理吗?



Compiler must faster then Interpreter-Compiler

JVM is an example of Interpreter-Compiler.

^.^

But ofcoz, we many always enhance the programming logic to archieve a better runtime. ^.^

21.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: violin
Posted on: 2004-06-24 15:58

感觉还是慢了,

22.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: tzutolin
Posted on: 2004-06-25 08:27

這類的報告, 若能找出一篇, 那麼, 結果相反的報告, 至少便能找出十篇. Java, 究竟還是比 C++ 慢. 不過, 仍然很感謝提供這些資訊的人, 讓學 Java 的朋友能夠開懷.

Best Regards,
tzutolin

23.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: samuelxp
Posted on: 2004-07-19 11:51

lifangning wrote:
呵呵,学过编译原理的大哥好牛~~~~
Java在虚拟机上运行,但运行C++的操作系统本身也就是一个虚拟机呀~~
仅靠一些纯理论的纸上谈兵谁不会呀?
有本事去研究研究人家的测试代码,看看人家的测试代码有什么问题,为什么会得到这样的测试结果~~~~~


操作系统不是虚拟机。
硬件实现虚拟机和软件实现差别是很大地。

24.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: colo007
Posted on: 2004-07-20 17:07

floater又出现了?

25.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: RollingWoods
Posted on: 2004-07-23 20:35

到CPU的Cache里,都是机器码,有什么可比的。

26.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: janage
Posted on: 2004-07-25 14:39

快与慢都是相对的。有必要这样比吗?

一个Java高手去写C++的程序与他写出来的Java相比,C++能快吗?

Java字节码是要通过JVM解释才能运行在CPU上的,而C++是直接运行在CPU上面的。但如果C++的程序结构不行,自然快不起来!

27.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: javaslave
Posted on: 2004-07-25 20:29

this topic has been discussed so many times on http://forum.java.sun.com, just do a search at the New to Java Tech. forum if u'd like to know more about it. To sum up, for the language itself, without any doubt, C++ is faster than Java. But we often have to consider many other factors as well for any application's execution speed, for instance, hardware's performance, network status if the app. is a distributed system. Personally, i dont think it makes much sense if we just take it completely out of context and talk about their execution speed alone.

28.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: dreamchenwen
Posted on: 2004-07-25 22:35

我觉得没有要比较的必要啊。所谓各有千秋阿。

29.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: michaelbeyond
Posted on: 2004-07-26 10:11

普通应用来说一点意义都没有,真的到了大型系统,纯粹的编程语言也是没有用的,还要看应用的架构设计,算法设计,和编程等等一切相关联的问题,这样就更没有什么好比较的问题了,有时候速度并不是所需要的,还要看能否解决问题。

30.Re:Java 比 C++更快??? [Re: lifangning] Copy to clipboard
Posted by: GWoo
Posted on: 2004-07-27 17:09

对于Web应用来说,网速的快慢才是影响用户感觉的关键


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923