Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

C++ vs. Java  RSS feed

 
paul wheaton
Trailboss
Posts: 22255
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anybody have some hot web pages comparing the speed of Java and C++?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll post the link before I verify it has what you want, but the Language Shoot-out http://www.bagley.org/~doug/shootout/ has comparisons on multiple criteria (speed, memory usage etc) for many common alrorithms running comparable code written in different languages.
Dave
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Scorecard displays a score per language based on custom weightings. The default, which measures only the CPU section of the tests, rates C++ (via the g++ compiler) as 4th with a score of 743. Java was 9th with a score of 703.
I'll have to look into where these numbers come from.
It looks like a particularly good score for Java.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java's performance isn't that bad compared to C++. Remember, the modern Hotspot Engine will compile critical parts of your code to native, too. The runtime optimizations might be even more effective than the static optimizations of a C++ compiler.
The biggest problem for *small* programs simply is the heavy startup time of the JVM...
 
Ran Pleasant
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've just completed a contract in which I built a prototype of a Java application that displays customer stock trading orders in real-time, data is received through a socket connection to a server. When compared to prototypes written in C++ and Delphi the Java application held up very good even though it had the slowest absolute speed (I do not have the numbers). For all three applications the bottle-neck was the network.
In another speed test, the Java prototype is fully completed - the C++ programmer still has plumbing to build. :roll:
[ January 17, 2003: Message edited by: Randall Pleasant ]
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Wheaton:
anybody have some hot web pages comparing the speed of Java and C++?

It depends on what you are doing. Need to process huge byte arrays over and over again. C will kick butt over Java because C has no boundary checking (among other things). Of course, the C program is more likely to contain boundary errors. (A friend of mine had to do this for an image manipulation project he was working on. The Java program took about 4 weeks to run and the C program took about 4 days.)
You can write an extremely efficient program in C if you know what you are doing. But that kind of requirement isn't found in a typical business application.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Thomas Paul:
It depends on what you are doing. Need to process huge byte arrays over and over again. C will kick butt over Java because C has no boundary checking (among other things). Of course, the C program is more likely to contain boundary errors. (A friend of mine had to do this for an image manipulation project he was working on. The Java program took about 4 weeks to run and the C program took about 4 days.)

That's correct - most people still think that Java is slower because it is interpreted. In fact, when it's slower it's most often because of inbuild security checks other languages are missing.
Notice, though, that the modern Hotspot Engine is able to remove some of those checks (as array boundary checks), if its analysis shows that it can't happen.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!