• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why Java run more slowly

 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
In addition to the interpreted language, what are other reasons that cause Java run more slowly than C++?
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Mike Yu:
Hi,
In addition to the interpreted language, what are other reasons that cause Java run more slowly than C++?


The fact that Java is interpreted really is the reason Java runs more slowly than a fully compiled language than C++. The fact that each line must be interpreted and then executed makes the language inherently slower than a language that is fully compiled and requires no interpretation. Of course, this does provide Java applications with greater portability than those written in C++.
Corey
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Corey McGlone:

The fact that Java is interpreted really is the reason Java runs more slowly than a fully compiled language than C++. The fact that each line must be interpreted and then executed makes the language inherently slower than a language that is fully compiled and requires no interpretation. Of course, this does provide Java applications with greater portability than those written in C++.
Corey


In fact, that is *wrong*!
With current hotspot technology, java programs *get* compiled to native code when run in a modern runtime environment. As this compilation can be based on dynamic analysis, the optimization techniques can be even more effective than the techniques used by static compilers like for the C++ language.
What really makes java slower than C++ are the additional safety checks. For example in C++ you can read past the boundaries of an array, cast an object to an illegal class etc. without even noticing!
So Java is trading performance for safety (and lowered maintenance costs).
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And to tell the truth I haven't seen any performance comparisons between a Java app and a C++ app that would make say that C++ is faster. I think Java is just as fast and sometimes faster that C++.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to Performance...
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java certainly was slower in its earlier days - now it's seldom a problem, really. Java does tend to be slower than C++ as it starts up. But once the JVM is started and classes are loaded, it is often as fast, and sometimes faster than, C++. Results can vary substantially depending on what sort of application you're working with - but well-written programs can be much faster than poorly-written programs. This is equally true in any language, and tends to be a more significant factor than language choice when trying to figure out why a given program runs slowly.
[ May 17, 2002: Message edited by: Jim Yingst ]
 
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Thomas Paul:
And to tell the truth I haven't seen any performance comparisons between a Java app and a C++ app that would make say that C++ is faster. I think Java is just as fast and sometimes faster that C++.


I would generally agree. For some scientific apps, with heavy number crunching, I think C/C++ is still a little faster; crypto is another example. You can match C only if you put a lot of effort into really optimzing your code. Generally I would still use C, or, more likely, use Java, but make native calls to C for the heavy math parts.
--Mark
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My understanding is that Java is slower as comparision to C/C++. Reasons are being an interpreted language, safety issues etc.
I had read benchmarks comparing Java - MFC - GNU C++ - VB, Java didn't do very well and was last in most of the benchmarks. But I read this benchmark 2-3 years ago, so things should have improved by now . I don't remember the website where I read this bench mark, but it was a non-microsoft website for sure. If I am able to find it, will post the link again.
But that doesn't make Java any less of a development option. There are many scenarios where I would love to have Java as the solution rather then C/C++.
 
Mark Herschberg
Author
Posts: 6055
8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gaurav Mantro:
My understanding is that Java is slower as comparision to C/C++. Reasons are being an interpreted language, safety issues etc.


As Ilja pointed out above, most Java programs are no longer intepreted, but rather compiles to native code. Hence there are asymptotically as fast as C/C++.
--Mark
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just my two cents: last year I implemented a 'matlab' like engine, biased towards large matrix manipulations in Java; the whole thing was programmable, extensible etc. etc. It took me less than two months to implement the whole thing; granted I had done some prototypes and design before those two months.
My department was curious about how fast this thing would be (they were more than satisfied by its performance, but hey, the sky wasn't the limit, heaven could be feasible ) if it were written in C++. C++ happened to be the 'lingua franca' at this department.
I started rewriting the whole shebang in C++ ... I had to come up with a reference counted memory management scheme, I had to defer the dynamic class loading elegance to a silly dlopen()/dlsym() kind of mechanism etc. etc. After six! months the rewrite was complete. The original +- 300 KB of .class files were replaced by more than +- 900 KB of .so files (don't you love those multiple template instantiations all over the place) and the grand result was: The Java version turned out to be just a meager 20% slower than the brand new C++ version ... and that exercise took me six months ... *sigh*
kind regards
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jos,are you going to maintain both code bases
[ June 16, 2002: Message edited by: Charlie Sturman ]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Charlie Sturman:
Jos,are you going to maintain both code bases


No I'm not, the C++ stuff was an 'off trail experiment' so I plea incompentence in all possible means your honour!
kind regards
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jos Horsmeier:

I started rewriting the whole shebang in C++ ... I had to come up with a reference counted memory management scheme, I had to defer the dynamic class loading elegance to a silly dlopen()/dlsym() kind of mechanism etc. etc. After six! months the rewrite was complete. The original +- 300 KB of .class files were replaced by more than +- 900 KB of .so files (don't you love those multiple template instantiations all over the place) and the grand result was: The Java version turned out to be just a meager 20% slower than the brand new C++ version ... and that exercise took me six months ... *sigh*
kind regards



That is beautiful. be nice to see the actual test results. Seems strange that Sun does not tout such things on the javasoft website since its the daily issue.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic