Forums Register Login

Java x C/C++ performance comparasion

+Pie Number of slices to send: Send
Hiya,
Does any body knows any reference of performance comparasion between Java performance agains C/C++. I am asking this because I am in a project where everybody complains concern Java performance, but I do believe in Java and on its performance. So, I would like to present some official paper to the guys on the project.
[ March 17, 2004: Message edited by: Nadilson Ferrreira ]
+Pie Number of slices to send: Send
Better give up, as you'll never convince the zealots except by showing them actual performance figures.
That would mean getting funding approved to code a pilot in Java and tuning it, and doing the same in C.
As the zealots control the budget (I guess) you won't get that money (after all, they know C is faster so why waste money proving what they already know...).
Fully optimised C code is likely faster than fully optimised Java code at runtime, but does it matter?
Most programs spend 90% or more of their time waiting for user input or other external resources, and that time won't be different (in seconds) no matter whether you code in Java, C, C++, Python or whatever.
The actual code might need a 10 microseconds more in Java than it does in C, but that's immaterial if it then has to wait 10 milliseconds (1000 times more than the difference in runtime) for a database operation to complete for example.
Such numbers are typical b.t.w.
Where Java shines in respect to C and C++ is the speed of development. Time to market is shorter, and so is (likely) the number of bugs (especially those related to memory management).
Of course as your team is mainly composed of people opposed to Java, they won't be very motivated to use it which doesn't help getting them productive...
Your best bet might be to try to switch to another project where Java is used (or is at least met with less hostility) and when that's a success and under budget slap the guys on the current project around the head with your results.
+Pie Number of slices to send: Send
If you think that numbers and arguments really help (which I doubt, too), Google has some nice references: http://www.google.de/search?q=performance+java+versus+c%2B%2B
+Pie Number of slices to send: Send
Java advantages shine in certain types of projects but not others. For example, a small utility that gets run frequently will look better in C because it will load and execute and exit before the JVM even gets going.
Conversely, for an application that loads once a day and runs for long periods, the load time will be immaterial.
An application that runs for a short period for an individual will never turn up errors in C++ memory management.
Conversely, a system application that stays running for weeks at a stretch will be much more stable if written in Java due to correct memory management.
Sooooo - where does your project fit in this spectrum?
Bill
+Pie Number of slices to send: Send
While I agree with everything posted so far, I worry that people might get the impression that one only uses Java if one doesn't care about performance. It used to be that Java had an order of magnitude disadvantage relative to good C++, and a lot of people probably think it still does. Heck, I did until recently.
I looked at a bunch of the Google links, and it appears that at least on Windows, the benchmarks show Java ranging from at worst a factor of two disadvantage (on a test featuring a lot of trig calcs that Java fared poorly on) to at best a slight advantage ... with most results being within 10-20%. For most purposes, there just isn't that big a performance hit for using Java any more.
+Pie Number of slices to send: Send
I read an article in 2002/ 2003 in the german Computermagazin c't, but don't find it online.
They compared c#, c++, java, pascal and something else, and an actual jvm with jit-compiler was FASTER than c++.
Of course there was a language-war about how to implement the algorithm, which compiler to use and which settings, and the kind of problems to solve...
Unfotunely pascal was even faster
+Pie Number of slices to send: Send
 

Originally posted by Stefan Wagner:

Unfotunely pascal was even faster


why unfortunately?
Pascal is a fine language. Using Borland compilers the executable code SHOULD be identical to C++ code when using the exact same implementation of an algorithm as the linker is actually used by both their C++ and Pascal compilers
As Pascal is easier to write it's likely possible to generate more optimised code using it though, making the result of Pascal outperforming C++ not that strange.
+Pie Number of slices to send: Send
You really can't convince someone of any advantage of using Java until they try it for themselves.
We use Java for our teaching language at my university and I was dreading having to take the class. I could not believe a state of the art university wasn't basing their computer science courses around a real important language like C++. I *hated* Java. Why? Some of my reasons weren't really rational and others were based on reasons not necessarily anymore. I thought Java was buggy and slow -- this based mostly on my initial experiences when Java was first released. I can remember a time that if I was browsing a website and the Java coffee cup logo would appear in the taskbar, I'd hit the Stop button because if I didn't Netscape would crash or hang. So after awhile I began to associate Java with pain -- or at least a pain in the butt! Also I remember hearing things like: Because Java was so buggy, you should only develop it on the Mac only because that was the buggiest and if it ran there, then it would run anywhere.
Also, I would always see the grey plain looking AWT screens on most of the applications I saw. What I didn't realize is that many of these applications were written by people who didn't care what the GUI looked like only that their application worked on through their website. I also didn't realize that the AWT look and feel has been updated by Swing.
Anyhow, after the first few lectures and writing some Java code of my own, I was hooked. What really sold me is how much easier writing a program becomes when you don't have to handle your own memory, or initialize your pointers, or wonder whats better a pointer or a reference, or try and figure out someone's #define hack so you can work with their code. I get many more successful builds than when I coded in C++.
So basically, if you had asked me in January about Java, I would probably have recommended C++. Speed is everything right? Now about three months of Java experience later, I will be recommending Java. If I *really* had to write an application in C++, I think that I could probably port it from code written in Java, though I haven't gone through the trouble yet.
Jody
+Pie Number of slices to send: Send
java is my favorite language(in general), but unless you have a processor that executes byte code for its machine language C/C++ will be faster. even interpreted, java has improved a lot though, and jit complilers make it even faster. no wonder C# is popular...all the advantages of java and it is compiled ahead of time into machine code.
my rule of thumb is: for general business apps use VB if possible. for apps where execution speed is everything, use C++. for everything else use Java.
i couldnt help but notice no one mentioned using assembly/machine language. :roll:
in the old days, i actually did.
[ April 18, 2004: Message edited by: Randall Twede ]
+Pie Number of slices to send: Send
 

Originally posted by Randall Twede:
java is my favorite language(in general), but unless you have a processor that executes byte code for its machine language C/C++ will be faster.


Don't be too certain.
Just in time compilers actually have one significant theoretical advantage over static compilers - they can ignore the parts of the source that are not actually used, and as a result, can generate smaller machine code.
In the old days, when everything was stored in main memory, this didn't matter, because the processor had to fetch from main memory anyway. Nowadays, though, there are usually a couple of levels of cache between the processor and main memory. Depending on the cache architecture, the smaller machine code generated by a just in time compiler may be able to stay resident in cache when the larger code would generate cache misses and require slower fetches from main memory.
I don't know whether this theoretical advantage has been translated into a practical advantage yet - though I can't think of a good alternate explanation of the tests which show Java running faster. If processor speeds and memory speeds keep diverging, though, the effect might eventually make Java faster than statically compiled languages in the general case.
My general rules of thumb would be, for general purpose business applications, make them web based and use PHP or Java on the server side; for really computationally intensive things use Fortran and assembly; for other things, use Java if they need to be cross platform and C++ if they need to take advantage of platform specific features.
+Pie Number of slices to send: Send
 

Originally posted by Randall Twede:
java is my favorite language(in general), but unless you have a processor that executes byte code for its machine language C/C++ will be faster.


When you have a processor that executes byte code, it will probably be slower than using a more common processor using a JVM. That's simply because the manufacturers of Java processors don't have the money to create the highly optimized architectures Intel, AMD etc. are creating.
On the other hand, Java's Hotspot Engine has two big advantages over C++ compilers. Both have to do with the fact that the code gets compiled at runtime.
First, the Hotspot Engine can compile optimized for the exact platform the code is running on. This can be quite significant - there are big differences between the processors.
Second, the Hotspot Engine simply has more data it can use for deciding about optimizations than a C++ compiler, specifically data about the runtime behaviour of the program.
+Pie Number of slices to send: Send
 

...unless you have a processor that executes byte code for its machine language C/C++ will be faster.


As Ilja Preuss and Warren Dew already stated, Java is not de facto slower than any other language, including C and C++. What if you could prove yourself? Well, try this link: Java vs C++ "Shootout" Revisited. This benchmark shows you that in many cases, Java outperforms C++. And the beauty of it all is that you can download the code and try it for yourself.

even interpreted, java ...


Java is not interpreted! The bytecode your javac generates is an intermediate language, and this bytecode will be compiled at runtime to machine code.

no wonder C# is popular...all the advantages of java and it is compiled ahead of time into machine code.


C# is not compiled ahead into machine code. The .NET platform uses an intermediate language (CLR) that can be compiled (exactely as Java) during execution time. And I quote: "The CLR's instruction set, was designed to be compiled to the native platform at install time or �just-in-time' (i.e. during execution) rather than being interpreted." - Peter Hallam, the development lead for the C# compiler. You might be mistaken by the fact that C# compiles to .exe files. But these same .exe files also run on FreeBSD, or on Linux using Mono for example.

Kind regards,
Kris
[ June 21, 2004: Message edited by: Kris Philippaerts ]
+Pie Number of slices to send: Send
Kris Philippaerts:

As Ilja Preuss and Warren Dew already stated, Java is not de facto slower than any other language, including C and C++. What if you could prove yourself? Well, try this link: Java vs C++ "Shootout" Revisited.

Unfortunately, as discussed in another recent thread here, that particular comparison test mostly just shows that the test preparer didn't know how to optimize C++.

I'm sure that when this thread was previously active, I came across some more objective tests (e.g., done by people who weren't already biased towards one side or the other). With enough googling, others should be able to also.
+Pie Number of slices to send: Send
Check this out: Java Faster Than C++?

This was linked on Slashdot on June 15th.

sev
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 981 times.
Similar Threads
design for java application
Object comparasion question
Comparasion of J2EE vs Mobile app. dev(Java ME,Android,iPhone,blackberry) in Indian market.
Where to find ans for mock test by Valentinn Cretazz
Stupid Astronomy Question
string comparasion
Now it China's Turn
Java Chess Game I made by my self
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:52:16.