Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

(Yet another) article on Java vs. C++  RSS feed

 
Tim West
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Out of interest...

...a new one is available here. Slashdot has discussion, some of which is surprisingly interesting.

My take on this eternal debate is that their relative performance is good enough that the decision should almost always be made on other grounds. (Exceptions to this exist, of course...)



--Tim
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And as usual the slashdot kiddies can't live in the real world and won't rest until they've found a way to discredit Java and anyone that dares defend it.

I stopped taking that bunch of idiots seriously a long time ago, now only troll there once in a while to have some fun to their cost (which they don't even seem to grasp most of the time).
 
Tim West
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree that they're not the most even-handed bunch, but a couple of posts pointed out some interesting/possibly conclusion-altering things about the way the tests were done. Whether or not similar points could be made from the reverse perspective (criticising the Java code) I'm not sure.

They do really have it in for Sun && Java though, eh?



--Tim
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course. But one has to see this benchmark in context.
The same code that yielded C++ a clear advantage in all categories a few years ago despite being poorly optimised now yields Java a clear advantage for the most part.
Whether code that is fully optimised for performance on either platform would show the same is irrelevant in the context of this particular benchmark which intended only to show the advances Java has made over the years.

Of course most production code is NOT optimised for performance so writing code specifically to yield optimal performance in a benchmark is hardly representative of the way the language will be used in the real world so this benchmark is likely closer to real life performance differences than typical benchmarks.

That's 2 details the dot-kiddies (r)(c), patent pending, leave out (and wouldn't comprehend if faced with it).
[ June 16, 2004: Message edited by: Jeroen Wenting ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep. It also strikes me that if it's even possible to say "oh, you didn't use this magic compile switch, then C++ would have been 11% faster on odd-numbered Pentiums," then it's just a moot point. If it's close enough that we have to argue about micro-optimizations, then it's obvious that it's really a wash.
 
Warren Dew
blacksmith
Ranch Hand
Posts: 1332
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is, with g++, many of those switches can make a huge difference in performance. That's one of the differences between the Java world and the C++ world: in Java, you don't have to worry about much other than writing the code properly, while in C++, the debug version you initially write is a far cry from the release version (unless you're Microsoft and selling slow software just gets the user to buy a new machine with a new copy of Windows on it). For example, the some of the slashdot posts point out the method test is primarily a test of method call overhead; enabling loop unrolling and function inlining could improve C++ performance on this kind of test by an order of magnitude. These are very standard optimizations in the C++ world, like using a JIT JVM in the Java world.

I don't think you're going to see a reasonable comparison benchmark done by a Java person, because Java skills just aren't sufficient to know how to make C++ code run fast, even if the person were motivated to do it. On the other hand, C++ people would probably come up with an unfair comparison benchmark, too.

I think the real difference this guy demonstrates is that with Java, it's easy to get to near optimal performance, while with C++, it's much harder, so hard that it often isn't done at all.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To me the most interesting thing was the HUGE advantage the -server JVM has over the -client in so many areas.
Bill
 
Emmy Rauch
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although I program mainly in Java I sometimes play with C++. There is one undeniable way in which C++ is better: console. There is no goto(x,y) for java and the amount of code required to have a password represented by *'s is simply ridiculous. Also, the speed of cout << "a" is significantly faster than System.out.println("a") in my experience. Sure it�s easier to make GUI�s in java than C++, but if that�s what you are really looking for then you should be using Visual Basic. Don�t act like Java is strictly better than C++ when it�s not; they both have their relative merits and complaining about how foolish people are who don�t realize that Java is clearly superior makes you just as foolish as the people you are complaining about. Don't claim that Java is faster than C++ when properly written- properly optimized C++ code includes inline assembly which is by definition faster than any psuedo-compiled language.

P.S. BTW, in the article there is a graph. What is this a graph of? The tests did show java as faster but the graph says "Bigger is better" and the Java bars are larger. I am going to run a test on println vs cout when later to see if what I said is correct
[ July 07, 2004: Message edited by: Emmy Rauch ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Emmy Rauch:
Sure it�s easier to make GUI�s in java than C++, but if that�s what you are really looking for then you should be using Visual Basic.


Unless you want your GUI's to be maintainable (I really like the LayoutManager concept of Java) and platform independent, I guess?

Don�t act like Java is strictly better than C++ when it�s not; they both have their relative merits and complaining about how foolish people are who don�t realize that Java is clearly superior makes you just as foolish as the people you are complaining about.


Well said!

Don't claim that Java is faster than C++ when properly written- properly optimized C++ code includes inline assembly which is by definition faster than any psuedo-compiled language.


Java is not a pseudo-compiled language. Java gets compiled at runtime to the machine language of the target system - and actually under certain circumstances can be more effective at inlining and other optimizations than C++ compilers, because it can analyze the actual runtime structure and behaviour of the system, as well as the structure of the runtime environment (such as the processor used).
 
Joe McIntyre
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope this isn't off topic, but this thread is closely related to a couple of questions I have. And keep in mind that I'm not a java guru, and don't even know C++, so pardon me if these questions are beneath the level of this thread. I'm doing some drawing stuff with java (similar to Adobe Illustrator, CorelDraw, etc) I have two major problems. 1) Java seems too slow for this kind of application. 2) I want people to download the software over a phone line modem connection, and the Java runtime download is too large. So I'm wondering if I could solve both these problems by compiling the java code to native code separately for each target platform (Apple, Linux, Windows, etc). Would this solve my problems?

(I wish Java WebStart and similar products could download only the part of the Java runtime that is required for the target application, but I don't think that will ever happen. Instead, all of use need to download the entire standard class libraries, including the "SpottedGreenFrogToe" class, just in case some kooky environmentalist wants to program a spotted green frog in Java. )
[ July 13, 2004: Message edited by: Wally Flint ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wally,

interesting questions, but I would advice you to start two new separate threads for those - you are much more likely to get good answers when the thread title matches your request...

And when you do this, don't forget to tell us more about in which way Java seems to be too slow.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!