Saturday, February 07, 2009

C# versus C++ versus Java performance comparison

The performance comparison of C#, Java and C++ was always a controversial subject. Many people who are unfamiliar with JIT'ed environments claimed anything runs on JIT is too slow compared to C++. On the other hand people who actually use Java and C# usually claimed the otherwise that performance impact is negligable. Here's a nice chart I've found that a friend in freenode IRC server pointed me. These benchmarks are done by Matt R Warren (aka Moridin8 in irc.freenode.net) and his original site is http://www.csharp-architect.com


According to below chart, choosing C++ just for the sake of performance doesn't seem very feasable to me. Remember : Engineers are expensive and servers are not!




31 comments:

pcdinh said...

Please run PHP and Ruby on Linux. PHP is not optimized for Windows. Therefore PHP is deadly slow on this platform

Artur said...

Please make sure you run with server jvm on windows - java is not using it by default (as opposed to linux).

If possible, make the benchmark bit longer - 3-4 seconds hardly gives any chance to dynamic optimization and penalizes longer startup times. One minute for java should be more than enough to offset those factors.

Jack Park said...

Engineers are expensive and servers are not!
Servers may be cheap, but the real cost of the energy to run those servers is increasingly more expensive. The fewer servers required to ship bits, the better.

Isaías Alves said...

if.. if.. if...

Java is the best language... have the perfect api with all resources needed to development.

Sorry PHP, sorry ruby, sorry microsoft.. But java is the best!!!

Erik Guerrero said...

Great chart and graph.
It would be very interested to compare the performance using multicore programming or concurrent or threaded programming.
For example, we had an application written in C# which had an horrible performance. However, we made some exercises found in the excellent book "C# 2008 and 2005 threaded programming", by Packt Publishing (http://www.packtpub.com/beginners-guide-for-C-sharp-2008-and-2005-threaded-programming/book), and we could multiply performance by more than 3,5 in a quad-core CPU.
Therefore, I think it would be great to see a performance comparison taking into account modern multicore computers.
Besides, the Garbage collector would enter in action. And, the results should be very interesting for the developers interested in the best performance.
I work with both Java and C#.

Isaías Alves said...

if you say about a garbage collectors. On this aspect, java and c# its equals... because the language patterns and design its very equals..

Uses of garbage collector set the java on the top of ranking... Yes.. show the graphic using this method.

And C#? Yes.. C# to.. Sun creates.. Microsoft Copies..

Good for .NET programmers...

Im to develop in Java and C# to...

But.. the .NET framework not help the C# language in performance and in a best programmer methods.

Thanks

Anonymous said...

What about memory usage ?

Anonymous said...

Hi,

I would actually like to see the code. I beleave, that your results are correct for typicaly written programms. But in C++ you can optimize and optimize and optimize until the last register is your best friend and the pipelines are your lovers.

Anonymous said...

I guess the numbers come from The Computer Language Benchmark Game (http://shootout.alioth.debian.org/) and/or the windows port at http://dada.perl.it/shootout/

Jesse said...

Can you please detail the compiler settings used for each compiler tool? Thanks.

Anonymous said...

A lot of fucking spam over here... Ruby 1.8 is old and slow. It should use Ruby 1.9

Anonymous said...

What configuration of server?
PHP correct working on Unix optimizet server.

Zsolti said...

"But in C++ you can optimize and optimize and optimize until the last register is your best friend and the pipelines are your lovers."

Yes, and you have to pay the development costs. That way we can say that hand written assembly code is the best... who the hell will pay out the 100x development time?

Isaac Gouy said...

All those things that previous commentators have said are missing from this "performance comparison"

- run PHP and Ruby on Linux
- make the benchmark bit longer
- multicore
- memory usage
- the code
- the compiler settings
- Ruby 1.9
...

are shown on the website these programs were taken from

The Computer Language Benchmarks Game

kimberly said...

When I bought my computer and I didn´t know how to use java graphics, so I decided looking for information in a webside and I found an useful information that helped me a lot.. Now I am interested in to do the best investment and I found a webside very useful and interesting called costa rica investment opportunities , I think it´s a very wonderful site.

Anonymous said...

Interesting post. Too bad it's completely inaccurate.
1) The claim in this article finds no ground in reality - the performance difference is noticeable by end users.
2) I find these numbers hard to believe. Really hard to believe - I mean, they show C# being faster than C++.
It doesn't matter how fast C# is, C++ will always be faster, because by definition it does less.

Anonymous said...

"Engineers are expensive and servers are not!"
Look around the world there are more Engineers than servers.

Anonymous said...

Thanks for the information

http://extreme-java.blogspot.com

Muhammad Azeem said...

This is a nice article..
Its very easy to understand ..
And this article is using to learn something about it..

c#, dot.net, php tutorial

Thanks a lot..!

Belch Echo said...

Would you please do a better graph? Use a bar chart or something.

Anonymous said...

"The claim in this article finds no ground in reality - the performance difference is noticeable by end users."
Facepalm... This is because C# is easier to learn => more unskilled novices make more software.
C++ is more difficult => there is less novices, more pros => more fast and robust software.
C# apps being generally slower doesn't mean c# is worse than c++ at all. It doesn't have to do anyhing with its performance. In good hands, any tool is nearly perfect.

Anonymous said...

>It doesn't matter how fast C# is, C++ will always be faster, because by definition it does less.

Seems you have little experience in both systems... C# _doesn't_ actually do more. .NET environment is basically the same C++ compiler except it does it on-demand. Its code output can be (and often is) 100% identical to that of C++. The only thing C# does "more", is forced garbage collection. You're right, if you're writing a hello world program. If there is a garbage collection while the program is printing "Hello, World!" then that might be problem.

But if you're writing a complex application, C#'s garbage collection is a plus. Why? Because C++'s ugly RIA does more. Imagine there a lot of functions, and each time it acquires, initializes and destructs. There is also reference counting out there -- and it does a lot more than C# as well (right to memory each time).

General memory allocation system does a lot more in C++ than in C# (it has bump pointer allocation).

C# may be still a little bit slower (thoough already comparable) just 1) it's not so mature as C++, still developing 2) Microsoft loves to do things gradually, to buy as many new versions as possible.

Anonymous said...

Good article. This is a good article explaining which is better for beginners. http://mytechrant.com/?p=6

Javin @ OutOfMemoryError in Java said...

This word makes the whole post classic "Engineers are expensive and servers are not", quite true and that's why Java rules because of ease of development and availability of expertise.

Hrishi Sharma said...
This comment has been removed by the author.
Hrishi Sharma said...

Java Devs say C# is inferior , whereas .Net developers bite th'm the other way round.........

I would love to listen to the views of those who are .Net(C#) cum Java developer..... :p

wholesale cheap jerseys said...

The server may be cheap, but the real cost energy to run the server is more and more expensive. The fewer the server may need to position the better.

Cheap Nike NFL Jerseys said...

If possible, make the benchmark bit longer - 3-4 seconds hardly gives any chance to dynamic optimization and penalizes longer startup times. One minute for java should be more than enough to offset those factors.

Arkadiusz Szulakiewicz said...

I have write nice article about caching object in C#. You can find it here: http://blog.szulak.net/programming/caching-objects-in-c/

Invest said...

Amazing insight. C++ runs the fastest on GNU Linux. For my developing needs, I choose c# for my work and Java for my own projects, because Java has free IDEs and C# needs Visual Studio. Performance on windows-wise, I prefer c#.

Anonymous said...

Can we get an update of this chart for 2014?