• 0

[C++ vs Java]


Question

I would be interrested to see some comparaisons in speed between C++ and Java applications doing the same thing.

Any suggestions on what kind of processing I could do to write test applications ?

The more CPU intensive, the better (I guess). I'll probably include some loops, some int & float calculations, some file read/writes, recursive functions calls... Any other ideas ?

Link to comment
Share on other sites

17 answers to this question

Recommended Posts

  • 0

In my experience, Java is simpler than C++, but it has a similar syntax, and works in a similar way. Java annoys me because of the VM, especially Sun's one, which I think is bloated. I assume Java would be slower, because of the virtual machine. For RAD/Simple Programming, I'd choose C#, but Java would be an acceptable choice. Programming in C++ can be difficult, but the end result is a fast, clean program.

Link to comment
Share on other sites

  • 0
In my experience, Java is simpler than C++, but it has a similar syntax, and works in a similar way. Java annoys me because of the VM, especially Sun's one, which I think is bloated. I assume Java would be slower, because of the virtual machine. For RAD/Simple Programming, I'd choose C#, but Java would be an acceptable choice. Programming in C++ can be difficult, but the end result is a fast, clean program.

Java is not overly slower in most types of calculations, but when you throw a GUI on, it seems to slow Java down a lot.

Link to comment
Share on other sites

  • 0

I don't really want opinions on which one to choose, or why...

I work with both daily. I have more than 5y exp. in c++ and something like 2y in java.

What i want to do is write an app in both language, and see if java or c++ is better for io for example, or functions calls, or floating point calculations, etc.

I want to do that because most ppl have opinions that aren't based on any facts, simply a 'feeling' or saying that a vm *needs* to be slower...

I'd like suggestion on what features I should test with...

I'll post my code and ask ppl for optimizations that could be done in both languages to see if the performance could be improved.

Link to comment
Share on other sites

  • 0

i was always under the assumption that java is slower than c++ in most applications, but i could be wrong... its been a good two or three years since i seriously made anything in java :p

Link to comment
Share on other sites

  • 0

C++ vs Java Comparison

A quick search on google turned this up. It shows that programs compiled with the Intel C/C++ compiler run the fastest. Not too supprisingly, the client VM for Java is the worst. The server VM for Java out-performs C++ in some cases. My guess this is because the server VM profiles the code before binary translating so it can make optimisations that the C/C++ compiler can't.

Link to comment
Share on other sites

  • 0

The Swing GUI toolkit gives the impression of slowness. If you want a proper toolkit that uses native GUI components where possible, use SWT.

Link to comment
Share on other sites

  • 0

Don't get too focused on which one is faster. Find out if they are fast enough and write your code in the language that is easier to maintain. Code maintenance is the one of the most expensive part of software engineering and means a heck of a lot more than whether a language/compiler gives you a 0.1s improvement in performance.

Also, be careful not to compare apples to oranges if you do a comparison. If you compare native code generated from C/C++ with Java bytecode that has not been converted to native code (possibly at runtime) then it is given which one will be faster. Keep also in mind that C++ and Java are languages and have no measurable speed, so you will in fact be measuring hardware speed, the optimization level of the generated code, etc.

Keep in mind that you will likely be measuring the optimization features of the compiler (and possible the JVM) if you do a comparison.

Link to comment
Share on other sites

  • 0

would like to see how java 1.5 stands against c++ now with its revisions.

my best test for speed and what we would do in comp sci is various sorting algorithyms, make an array of 30,000 random numbers, than do a timer and a quick sort or something, the code will be similar in both languages only minor changes.

Link to comment
Share on other sites

  • 0
Don't get too focused on which one is faster. Find out if they are fast enough and write your code in the language that is easier to maintain. Code maintenance is the one of the most expensive part of software engineering and means a heck of a lot more than whether a language/compiler gives you a 0.1s improvement in performance.

I'm not looking for the best language to use for a specific case. I use Java daily at work. I don't have a choice. It works well and we do what we have to do in Java. I also use C++ daily on multiple personnal projects.

Keep in mind that you will likely be measuring the optimization features of the compiler (and possible the JVM) if you do a comparison.

Well, I don't see how I could check the 'speed of a programming language'... so yes, I know I'll be making comparaisons between implementations of their respective compilers, etc.

I don't want to measure how long it takes to write the actual code or maintain it either. This depends on the programmer mostly.

my best test for speed and what we would do in comp sci is various sorting algorithyms

Good idea! Sorting algorithms is something used often enough in real life to make sense in a comparaison.

Link to comment
Share on other sites

  • 0

They should be close, but Java can't technically be faster than C++ because it has to pass it thru a VM which adds cpu cycles. A hello world program may be just 0.00000000000000003rd of second diffence between the two, but C++ would be faster.

Link to comment
Share on other sites

  • 0

That's a misconception dating form the time Java was invented.

As I said before, if u can't answer the one question I asked, please restrain from replying.

Link to comment
Share on other sites

  • 0
They should be close, but Java can't technically be faster than C++ because it has to pass it thru a VM which adds cpu cycles. A hello world program may be just 0.00000000000000003rd of second diffence between the two, but C++ would be faster.

Once the code is compiled into machine code for the specific processor, why should it be any slower?

Link to comment
Share on other sites

  • 0

I'd like to add my comment here - it's actually not the question of who is faster. Java or C++.

These days almost nobody works with low-level programming.

So, it's all related to the environment you run your stuff.

It can be application server or framework and of course your own business logic...

Add here the tunning of the environment itself (easiest sample is JVM tuning - it's different for each application).

So, in a practical manner (or let's say end user point of view) - speed is the result of too many components...

Anyway, I did not want to say that this thread is useless, just wanted to say my IMHO about speed comparations for current technologies.

Link to comment
Share on other sites

  • 0

C++. But I say C rules over them both. C++ is faster, smaller, easier (IMHO), and has many other points. If you want you program to run on any platform, use wxWidgets, better than Java. I think Java should change...

Link to comment
Share on other sites

  • 0
C++. But I say C rules over them both. C++ is faster, smaller, easier (IMHO), and has many other points. If you want you program to run on any platform, use wxWidgets, better than Java. I think Java should change...

So, have you not seen SWT and AWT, then? They are GUI toolkits for Java which utilise the native OS toolkit where possible. Its own widgets look quite nice, also.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.