![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Feb 2006
Posts: 214
Rep Power: 0
![]() |
Java slower than c++
Now i'm new to java just learning it in school right now and i want to know why is it slower than c++?? now with c++ you declare memory on the stack while in java i don't think you can. Is that the primary reasson that it is slower?
Has it to do with the fact that java is an interpreted language while c++ isn't. Please can someone explain this to me. Sorry for the newb question. |
|
|
|
|
|
#2 |
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3
![]() |
It's mainly about Java being interpreted whereas C++ is compiled.
|
|
|
|
|
|
#3 |
|
Professional Programmer
|
http://www.idiom.com/~zilla/Computer...benchmark.html
The : "Java is slow" - is becoming more and more an "urban mith" so to speak. Yes, an application starts slower with java, but from then one, the differences aren't that greate. And with each new jdk version, things are getting faster. http://www.javaworld.com/jw-02-1998/jw-02-jperf.html
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,221
Rep Power: 5
![]() |
Java being slower than C++ is no urban myth. There are some cases where well written Java code can out-perform well written C++ code, but they're exceptions rather than the rule. Things like JIT in Java can give better performance, if your code does things over and over, as your code is optimised to run faster when it is run more often, but YMMV as to what code it works well with and what gains you get because it relies on internals of the virtual machine.
The JVM (which interprets Java byte codes) is a performance bottleneck for a Java program, although techniques like JIT do improve things a lot but that depends on the implementation of the virtual machine. C++ does not have a virtual machine, so no such bottleneck exists --- the primary bottleneck on performance of a C++ program is always quality of the code and libraries the program used. Java still has that bottleneck. A high quality C++ compiler optimises for the target machine, which a Java compiler does not. JIT can achieve the same effect for Java (and potentially do a better job as it occurs at run time, so can optimise execution to address actual hotspots in code) but JIT functionality is at least as difficult to implement well as high quality compiler optimiser. |
|
|
|
|
|
#5 | ||
|
Battle Programmer
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 763
Rep Power: 3
![]() |
I stand somewhat corrected. I did find this humorous though:
Quote:
Quote:
However, both articles were interesting, especially the first. |
||
|
|
|
|
|
#6 | |
|
Programmer
Join Date: Feb 2006
Location: Columbus, OH
Posts: 84
Rep Power: 3
![]() |
Quote:
![]() |
|
|
|
|
|
|
#7 |
|
Sexy Programmer
|
Java is compiled into machince language and then the JVM runs the machine code and executes the program, a lot of people say Java is slower than C++ but also its been proven that its actually if anything a little faster than C++, I've read a lot of documentations on Java and C++ and then average out on run-time!
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#8 |
|
Hobbyist Programmer
|
Actually isn't java compiled into java byte code and then interpreted by the jvm? I know there are compilers that convert it into native code, but I was under the impression that the jvm interprets the byte code, not native code.
|
|
|
|
|
|
#9 | |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Quote:
Java bytecode has the advantage of being platform independant. With Java, you don't have to worry what machine you're programming on, and you don't have to worry about library or DLL conflicts - if the JVM runs, your program will probably run, too. C++ has the advantage of being faster, because it cuts out the JVM middleman, and in many cases more memory efficient, as JVM instances can't share libraries, IIRC, whilst C++ programs do this all the time. Java isn't going to be faster than C++, because the JVM slows it down. Java may have some more efficiently programmed libraries than C++, but that's another story altogether. In general, Java is several times slower than C++. |
|
|
|
|
|
|
#10 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Funny how "urban myths" come about because a machine runs at 3 GHz instead of 2 MHz. Nothing real about that chit, of course.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|