views:

1293

answers:

5

Taken out all the obvious caveats related to benchmarks and benchmark comparison, is there any study (an array of well documented and not biased tests) that compares the average execution speed of the two mentioned languages? Thanks

+2  A: 

What is faster- Java or C# (Or good old C)?

rahul
+3  A: 

The best comparison that I am aware of is The Computer Language Benchmarks Game.

It compares speed, memory use and source code size for (currently) 11 benchmarks across a large number of programming languages. The implementations of the benchmarks are user-submitted and there are continouous improvements, so the standings shift around somewhat.

All comparisons are done on Linux, so it is C#/Mono that is measured and not C#/Microsoft.NET. But it is my impression that those two are comparable in speed nowadays.

Currently Java is winning on speed, but C#/Mono is winning on memory use.

Rasmus Faber
I don't think that comparing Java to Mono makes much sense, MS' .net runtime is probably a lot faster than Mono.
ammoQ
@ammoQ: That would have been my guess, too. But I looked it up and the following article seems to indicate that the performance is comparable: http://geekswithblogs.net/CISCBrain/articles/Mono_vs_dotNet_Performance_Test.aspx .
Rasmus Faber
@ammoQ, Any particular reason to believe that .NET is faster than Mono per default?
Thorbjørn Ravn Andersen
@Thorbjørn: No, just a feeling in the gut and some experiences so out-dated I won't bother telling. Some discussion about it (including contributions from Jon Skeet): http://www.eggheadcafe.com/software/aspnet/32289725/benchmarks-java-vs-net.aspx
ammoQ
Your assumption is correct. I remember seeing this a while back. Look around for benchmarks on the Vala language (essentially c# thats gets translated to standard c), it had a benchmark of mono vs .net
jdc0589
@Rasmus Good find! The article itself is from 2005 but people keep running benchmarks and post results back in comments.
Andrew
A: 

This could invite a flamewar, but hey, it's my opinion...
First of all, if your site runs too slow, you'll need better hardware. Or more hardware and add load balancing to your site. If you're Google, you'll end up with huge server farms with thousands of machines that will seem to provide a lightning-fast performance, even if the sites themselves are developed in some outdated language.
Most languages have been optimized to get the best from their hardware and will outperform any other language in this specific environment with a specific setup. Comparing languages won't make much sense because there are thousands of techniques to optimize them even more. Besides, how do you measure performance to begin with?
Let's say that you look at execution speed. Language X might perform some task 2 times faster than language Y. However, language Y is more optimized for running multiple threads and could serve 10 times more users than language X in the same amount of time. Combine this and Y would be much faster in a client/server environment.
But then install X on an optimized system with an operating system that X likes a lot, with additional hardware, a gadzillion bytes of memory and disk space and a dozen or so CPU's and X will beat Y again.
So, what's the value of knowing the execution speed of languages? Or even the comparison of languages? How do we know that the ones who created the report weren't biased? How are we sure that they used the most optimal settings for every language? Did they even write the most optimal code to be tested? And how do you compare the end results anyways? Execution time per user? Or total execution time?
Back to languages X and Y. X runs a task in 2 seconds but it supports only 10 threads at the same time, thus 10 users. Y needs 6 seconds but serves up to 50 threads at the same time. X would be faster per user. In two seconds, X has processed 10 users. In 6 seconds, X has processed 30 users. But Y would have processed 50 users by that time. Thus Y would outperform X when you have lots of users, while X would out-perform Y with a low amount of users. (Or threads.) It would be interesting to see reports mentioning this, right?

Workshop Alex
This answer is more a comment, than an answer.
Thorbjørn Ravn Andersen
Basically, I'm saying that you just can't compare two different languages, even if they're very similar, like C# and Java are. Thus a comparison of languages is useless, unless you're comparing for a very specific area.
Workshop Alex
A: 

Here's a nice recent study on the subject:

Numeric performance in C, C# and Java

Peter Sestoft ([email protected])

IT University of Copenhagen Denmark

Version 0.9.1 of 2010-02-19

Abstract:We compare the numeric performance of C, C# and Java on three small cases.

...

ohadsc
The conclusion from the paper: "The experiments show that there is no obvious relation between the execution speeds of different soft- ware platforms, even for the very simple programs studied here: the C, C# and Java platforms are variously fastest and slowest."
Thorbjørn Ravn Andersen
A: 

If you are looking only for startup performance, this is a good benchmark: http://www.codeproject.com/KB/dotnet/RuntimePerformance.aspx

dmihailescu