Java vs C++ benchmarks

This forum is reserved for everything you want to talk about. It could be about programming, opinions, open source programs, development in general, or just cool stuff to share!
xrvjorn
Earned a small fee
Earned a small fee
Posts: 15
Joined: Thu Apr 13, 2006 4:27 pm
Location: Sweden

Java vs C++ benchmarks

Post by xrvjorn »

Since this is a forum for cross platform developers, I guess that a few of you have looked into Java. It has become quite a nice language after the addition of parameterized types (C++ templates) and enumerated types, so I did some googling for benchmarks. Apparently, there are lots of benchmarks out there, showing that the execution speed of Java is on par with that of C++. Still, all Java apps I've seen are sluggish. The last one I tried was a UML designer tool (ArgoUML) that took forever to start and had quite an unimpressive performance once started.

Is there some setting in the JRE control panel I've missed, or are the benchmarks run under very special conditions?

The app I'm working on now, is handling quite a lot of bitmaps, so I haven't considered using Java for it. I'm just curious how Java can perform so well in the benchmarks, while Java apps perform so badly on my computer.
cul8r
/J
rickbsgu
Earned a small fee
Earned a small fee
Posts: 16
Joined: Wed Nov 08, 2006 2:32 am

Post by rickbsgu »

I've been wondering this, myself - especially with the advent of the SWT, which is supposed to be much more efficient than Swing, and provides better native emulation/hooks.

About nine years ago, I was working on a project redesign and Java was a consideration. We ultimately opted out and went with C++/Qt, but there were strong proponents for going to Java.

The claim was that it could be made to go as fast as C++, but you had to do a lot of profiling and optimization to do it. Part of which meant that everyone who worked on the project had to be very expert in the language.


Part of what you're seeing, I suspect, has to do with the quality of the developers. I note that people who are trained in the newer languages like Java and C# tend to use rather expensive container constructs and the like, un-necessarily, chewing up resources. In particular, I see maps (or, worses - dictionaries/hash-tables) overused where simple arrays or even bit-vectors would do the job.

That kind of thing can nail you in C++, too, but C/C++ folks usually are more cognizant of system resources, and it comes through in the coding.

And then there is the VM - waiting for the VM to start up can be a real drag. Maybe you can write optimized code, but the VM overhead just on startup seems to be real killer. Plus, it's a rather large installation piece, and versioning can nail you.



Maybe things are better, now - like I said, this was 9 years ago. Hardware's gotten a lot faster, there's lots more memory available, and Sun hasn't been sitting on their hands.

rickb
S.Volkenandt
Knows some wx things
Knows some wx things
Posts: 26
Joined: Tue Nov 14, 2006 1:51 pm
Location: Duesseldorf, Germany

Post by S.Volkenandt »

Might be off-topic, but please don't mix C++ templates with Java Generics. They are completely different things (although they might offer the same possibilities at first glance). There is no such thing like C++ templates in the Java language.
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

in general, a Java just-in-time compiler creates code that's almost as fast as c/c++ code, sometimes even faster, because it can use SSE optimizations. But the compilation takes place the first time a piece of code gets executed, so in the beginning it takes much longer.

Unfortunately everything related to GUI elements is usually a little slow and makes Java applications feel a little "unresponsive", but on todays PCs it's not really that bad.

And i have to agree with rickbsgu, one major reason for bad performing Java applications are the Java programmers. They tend to write clean and well-structured code, but they don't care about performance. They assume a PC that has unlimited speed and unlimited RAM. C/C++ programmers usually think a little more "low-level" and know what operations can be expensive in terms of performance.

Additionally, in C++ you can use dirty tricks that are usually not possible in Java, e.g. casting an RGBA pixel to an unsigned long or stuff like that ;)

Summing up, i think it's definitely possible to create fast and professional applications in Java if you know what you're doing.
Use the source, Luke!
gururamnath
Super wx Problem Solver
Super wx Problem Solver
Posts: 466
Joined: Sat Sep 18, 2004 2:49 am
Location: California, USA

Post by gururamnath »

Java does outperform C++ only in very few areas. People tend to overrate these performance.

Have a look at the benchmark of various languages at :

http://shootout.alioth.debian.org/gp4/b ... lang2=java


-Guru Kathiresan
uj
Knows some wx things
Knows some wx things
Posts: 37
Joined: Mon Sep 13, 2004 7:05 am

Re: Java vs C++ benchmarks

Post by uj »

xrvjorn wrote:I'm just curious how Java can perform so well in the benchmarks, while Java apps perform so badly on my computer.
Java has improved a lot lately. I'm using Java version 6.0 to run Eclipse (a popular IDE) on a 6 years old PC and it's great.

I think Java now is fast and slick enougth for most mainstream desktop applications. (I'm not even sure the Eclipse consortium would opt for SWT could they start over again with the Swing of today). It's only if you have very, very special needs C++ should be necessary for efficiency reasons, (like if you want to write a JVM for example :)).

With Java you get automatic memory management, threading, multiple platforms, a standard GUI and lots of other standard librararies. If you use a static compiler the drawbacks are minimal.
xrvjorn
Earned a small fee
Earned a small fee
Posts: 15
Joined: Thu Apr 13, 2006 4:27 pm
Location: Sweden

Post by xrvjorn »

uj wrote:Java has improved a lot lately.
That's what I keep hearing, so I'm surprised by the sluggish performance of Java apps on my computer, ArgoUML being the latest dissapointment.
cul8r
/J
vdell
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 536
Joined: Fri Jan 07, 2005 3:44 pm
Location: Finland
Contact:

Post by vdell »

xrvjorn wrote:
uj wrote:Java has improved a lot lately.
That's what I keep hearing, so I'm surprised by the sluggish performance of Java apps on my computer, ArgoUML being the latest dissapointment.
Well even if Java has been improved, the application can still be the problem if it has been coded badly.
Visual C++ 9.0 / Windows XP Pro SP3 / wxWidgets 2.9.0 (SVN) | Colligere
lowjoel
Part Of The Furniture
Part Of The Furniture
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel »

From what friends tell me... Java is slow under Windows only because Windows likes to swap a lot of the VM's memory to the page file... and we know that page faults can take a lot more instructions to access memory than taking them directly from RAM. If we follow this argument then Linux should be less of a problem.

I'm not sure, but it's my two cents.

Joel
xrvjorn
Earned a small fee
Earned a small fee
Posts: 15
Joined: Thu Apr 13, 2006 4:27 pm
Location: Sweden

Post by xrvjorn »

That could be interesting to test, I'll check that on my Ubuntu VMWare machine when I get back.

I completely forgot about Azureus, the Java BitTorrent client. It takes a while to start and is quite a memory hog, but once up and running, it's fast, responsive and even has a native look and feel.
cul8r
/J
uj
Knows some wx things
Knows some wx things
Posts: 37
Joined: Mon Sep 13, 2004 7:05 am

Post by uj »

Well even if Java has been improved, the application can still be the problem if it has been coded badly.
It's hard to pinpoint the problem with so little information. It may very well be that the PC doesn't have enougth resources, or something with the JVM version or, or, or.

I can only say that I've been using Java for a long time and the performance has been really crappy almost all the time but it started to improve around 2003 and is now remarkably good. I think it's fair to say that Java has, after 10 years, finally caught up with its hype.

I think a good programmer can write a better program in C++ than in Java. The problem is that the effort will be so much higher and the gain may not even be noticeable to a user. And Java has so many goodies to throw in.

For example if I were to write a portable application in C++ I would need to select a portable GUI. The choise between say wxWidgets and QT is like choosing between pest and cholera. With all due respect one cannot claim that wxWidgets is a modern OO based package, or that QT is very affordable in a startup situation. In Java there's Swing just for the grabbing and it's both.

Well, I may still go for C++ just for the heck of it :). Like many others I'm kind of drawn to the complexity. But most likely I write the bulk in Java, including GUI and 3D modelling, and just break out the heavy computing stuff into an "engine" written in C++.
xrvjorn
Earned a small fee
Earned a small fee
Posts: 15
Joined: Thu Apr 13, 2006 4:27 pm
Location: Sweden

Post by xrvjorn »

Book recommendations?

Considering some input in this thread, I figure it's time for me to take a deeper look at Java. Can anyone recommend any Java books that go into the sort of detail an old C++'er would want? By that, I mean information about the cost of using certain containers and language constructs, and explanations of the type you find in Scott Meyers excellent "Effective C++".
uj wrote:Well, I may still go for C++ just for the heck of it :). Like many others I'm kind of drawn to the complexity. But most likely I write the bulk in Java, including GUI and 3D modelling, and just break out the heavy computing stuff into an "engine" written in C++.
Mixing Java and C++ sounds interesting. How do you do it? JNI?
cul8r
/J
loptr
Earned some good credits
Earned some good credits
Posts: 110
Joined: Tue Jan 23, 2007 12:22 pm
Location: Kiel, Germany
Contact:

Post by loptr »

i'd say: hands off JAVA!

only had problems and major problems with it, starting with the performance (well, not "starting", in fact) up to the very creation of bytecode...

unfortunately, java code does not seem to be compatible to older versions, so if you've got an app it might (and probably will) be the case that you'll have to install an older version than that you are normally using...

as for the performance: i'd rather keep an eye myself than letting a garbage collector do the work. i, personally, would get lazy if i didn't have to look at the performance...
lowjoel wrote: From what friends tell me... Java is slow under Windows only because Windows likes to swap a lot of the VM's memory to the page file... and we know that page faults can take a lot more instructions to access memory than taking them directly from RAM. If we follow this argument then Linux should be less of a problem.
seems so. once had a task at university (long, looong ago ;) ): writing a "Battleship" app. worked fine under linux, but was the hell under windows (response time to mouse click often greater than 20 secs!!!)
krzysiek_t
Earned a small fee
Earned a small fee
Posts: 23
Joined: Tue Jul 11, 2006 1:36 pm
Location: Poland, Warsaw
Contact:

Post by krzysiek_t »

xrvjorn wrote:That could be interesting to test, I'll check that on my Ubuntu VMWare machine when I get back.

I completely forgot about Azureus, the Java BitTorrent client. It takes a while to start and is quite a memory hog, but once up and running, it's fast, responsive and even has a native look and feel.
Azureus has many nice features, but it's a heavy piece of app. After some days of using it (under Linux!) I was surprised how much my PC was more responsive, when I close Azureus.

So maybe Azureus is responsive (comparing to other Java-apps), but my computer's performace was significantly decreased when Azureus was running. So I don't use it anymore :-D
xrvjorn
Earned a small fee
Earned a small fee
Posts: 15
Joined: Thu Apr 13, 2006 4:27 pm
Location: Sweden

Post by xrvjorn »

I've made the same experience recently. I thought Azureus was responsive when I started to use it, but now I've noticed that it's only true as long as it's the only app running. It's too much of a resource hog.

Trying out different UML drawing tools, I tested the one that's included in Suns IDE. It's slower than anything I've tried since the dBase menu interface 19 years ago. When you right click in the drawing pane, there as a delay for about 1 second before the context menu pops up. Click-and-drag of a drawing element has a 1-2 second delay before you can see the element being dragged.

Considering that the tool comes from Sun themselves, it's a very unimpressive showcase of what Java can do.

I'll still have to learn the Java and Swing, though. It seems unevitable these days.
cul8r
/J
Post Reply