Java Vs. C#: Which Performs Better In the 'Real World'?
Nerval's Lobster writes "Software developer Jeff Cogswell writes: 'Let's compare Java and C#, two programming languages with large numbers of ardent fans and equally virulent detractors. I'm not interested in yet another test that grindingly calculates a million digits' worth of Pi. I want to know about real-world performance: How does each language measure up when asked to dish out millions of Web pages a day? How do they compare when having to grab data from a database to construct those pages dynamically? The results were quite interesting.' Having worked as a professional C# programmer for many years, Cogswell found some long-held assumptions challenged."
When talking about large-scale websites the language is hardly relevent. There are as many high-traffic sites running on C#, Java, PHP or whatever. When facing large scale other factors play a much larger role. The only exception is when you're talking Facebook or Twitter scale: Facebook has practically reinvented PHP and also has some parts of their code in C (or C++, not sure) and Twitter made a switch from Ruby to Scala in order to handle the onslaught of users. The results mentioned in the article (accepting 2000 requests takes 600ms longer when using simple code) are not that interesting in this context.
As your worst developer on the team.
I've used both and really haven't seen issue with either. I have a slight preference for C#, personally, but it all comes down to your design, architecture, and implementation that will slow you down.
I personally would expect one to win in some regards and the other to win in others. My concern is that C# is too tightly bound to MS platforms. Java isn't perfect, it isn't the write once run everywhere that was promised, but the port from Java on MS to Java on Linux, Mac ... will most certainly be better.
That is enough that I would prefer Java over C# on my projects. Of course there are always outside parameters that might be enough to tip the scale.
This would be the browser plugin you're talking about? Websites are not served up by browser plugins. Stop spreading lies.
I have seen it often said that when a slashdot headline ends in a question mark then the answer is no.
C# programmers get paid more.
Most linux users don't know this, but the man pages were named after Chuck Norris. Chuck Norris fsck'ing hates noobs!
Before I get modded troll, I'd like to point out that there is a really awesome C++ toolkit for web development and it will blow your mind. It's called Wt and it makes your applications fully OOP and a joy to develop in. One really awesome feature is that it is Boosted and another awesome feature is smart with regard to data. It will use where apropriate (usually you use the AJAX version of a control or mark a function for export to javascript) AJAX rather than statically filling your page. The result are some really easy to code fast websites.
Slashdot's rate-of-post filter: Preventing you from posting too many great ideas at once.
These tests were also just as simple as calculating Pi a thousand times. Based on the description, I was hoping for some tests where a website with a dozen or so complete views with significant bindings were created in both Java and C#. Instead it was just an HTTP request or a page that printed the date.
Different frameworks and web servers are going to use varying amounts of overhead, so simple tests really only calculate that overhead. If you are going to provide benchmarks that actually have some meaning then they need to test complex enough behavior to mimic real world usage.
These tests basically just show that Tomcat is faster than IIS for simple scenarios, or perhaps that ASP.NET MVC 4 adds more overhead to page requests than JSP does. Whether this overhead is meaningful when you are processing rich real world web pages is not covered by these tests.
-- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
The question is would you like to be hung or firing squad neither of them is very good.
No sir I dont like it.
C is the clear winner. Maybe that why its 1 number in TIOBE Programming Community Index
However choice of programming language has a lot to do with what you want to do.
If you want to create jobs to processing millions of records locally, C/C++ would be better.
If you want to have secure web based jobs, Java would be better.
If you want to create Windows GUI applications, C# would be better.
Basically its horses for courses.
This article was obviously written by someone who has no idea what the state of the art is in performance web serving. If you know anything about high scale web technology, skip it.
.Net framework is fast, the ASP.net framework will be. That isn't the case. Running load testing on hello world test cases is silly. If you are interested in the real world, try testing with real world applications. The author also doesn't seem to understand that the JVM or .Net runtime will compile bytecode using JiT methods (Just in Time compiling). Finally, if you have skilled developers, it doesn't really matter what language you use. Architectural issues like data storage and caching are much more important than language.
Where to start complaining? Don't roll your own http server. You probably don't understand what you are doing, and you will get weird results. Using Windows as a platform for a java web server is pretty silly. The author incorrectly assumes that because the
Test 2: A function to generate a "full web site", (actually a simple web page with all the elements and trivial content). Java beats C# hands down.
Conclusion:
1. The testing guy has absolutely no idea of how to write low level function efficiently.
2. The testing guy's idea of a "full web site" is woe fully inadequate. He could have been the guy designing "full continental breakfast" in Roach Motel Inc.
sed -e 's/Chuck Norris/Rajnikant/g' joke > fact
"Real World?" If we're all not in the real world then we must be living in imaginary space then. Seriously, I see the C#/Java thing coming down to a matter of enterprise choice vs. performance of the language. You'll find big shops running WebSphere/Weblogic and those running JBoss to deploy enterprise apps. There's still a lot of folks deploying with tomcat, which is a great tool. Microsoft has done well over the past few years in improving IIS / .NET scalability where it now can compete with Java EE deployments. 5 years ago you couldn't say that but now the differences are becoming more narrow. I like Java and use it. I like C# and use it as well. My biggest concerns with both is that largely, they're in the hands of two very large vendors. Java has at least more open push on it but again, Larry Ellison will dictate largely what happens to Java and IMO he'll milk it for every penny he can get. C#/.NET not only sells OS licenses for MSFT but it also gets used as a toy as well.
It would be really nice I guess if both of these were truly in the public domain as to prohibit Oracle and MSFT from having direct control over how the languages evolve and are licensed.
Harrison's Postulate - "For every action there is an equal and opposite criticism"
It's a trap to try and make us look at TFA.
factor 966971: 966971
Graphs and charts, that brilliant and extremely high demanding tech from the XV century, that still didn't manage to be available to author of the study.
* Dalvik is not Java. While the Java programming language is available for Dalvik, together with a subset of the J2SE library, the runtime itself is unrelated. .NET" is kinda meaningless, neither does Win32. However, you certainly can build Metro apps in .NET. http://blogs.msdn.com/b/dotnet/archive/2012/04/17/net-for-metro-style-apps.aspx
* Windows 8 Metro "does not use
* The comment about the author of the article testing Java "by using a C# client" is bizarre and misleading. A language had to be picked, with the choice having the same impact on both tests. Chosing to test a Java server with a Java client, and then a C# server with a C# client would cause the test to be different in both situations and render the test results invalid.
* The author of the article concluded that Java was generally faster than C#, not that "it was a dog".
* Other than that, your comment is completely 100% correct. Possibly. Or maybe I didn't check.
You are not alone. This is not normal. None of this is normal.
The C# runtime doesn't interpret bytecode. It's all JITted before execution. Always.
Karma: Poor (Mostly affected by lame karma-joke sigs)
Today, most of (if not all) the reasons for choosing a language are subjective instead of objective (not objective-c). Languages are so similar (at least the fundamentals, not talking about Brainfuck-lang here) that you pick a language based on the platform it targets or just personal feelings.
In short, the Microsoft fanboys avoid more Linux-favored languages (and don't even think about Apple languages); Apple fanboys avoid more Microsoft-favored languages; and Linux fanboys avoid more patent-encumbered, closed-source languages and ones requiring to purchase an IDE/etc. for development. All fanboys avoid what they perceive as "diseased languages" like the plague. However, they will still touch these diseased language every now and then because either they have to for a job or out of pure curiosity.
Being a Linux fanboy, C# is my bubonic plague. This is also in part growing up using Microsoft Visual Studio 6 for C++. For the haters, I actually loved this IDE, but then I found out that none of my code would work on other platforms or even other compilers with Win32 such as Borland++, g++, etc. (we all remember how a variable in a for-loop wouldn't be contained to just that block... terrible). And then when exploring other languages/environments, I couldn't believe my eyes when I could actually see library-level source code -- you have no idea how useful this is. Even though I'll admit that Microsoft has gotten a little better about this (although they still tried to spread FUD using the DroidRage campaign), it's not worth it to me. They've already lost my faith in them as a customer, and I can't see myself ever returning.
Now, a good study would be to remove all of this and determine what languages are either faster to code in, easier to debug/maintain/extend with enterprise-level code, or more readable. But would this study even be useful? The differences would be so minute. Scripting languages are going to be faster to code in, so what's the fastest scripting language to code in? Object-oriented languages will be the easiest to debug/maintain/extend. As for readability, who knows? It's so subjective. We'd have to get a large, random sample size of people that have never seen a programming language before.
Having said all of this, I still appreciate this guy doing the study. Apache has always made top-quality code, and it's good to see that TomCat lives up to it.
Finally, as for sheer speed (and needs to be at least easier than assembly), C will always win.
The G
Really? Why do Oracle claim ownership of the code and even the api to company like Google? Threatering everyone who implement their variant of Java? On the other hand most of the C# library have been release the source code and the language is itself fully approved by EMCA and ISO (check wikipedia for reference), something Java is not (Because Java lacks any formal standardization recognized by Ecma International, ISO/IEC, ANSI, or other third-party standards organization, the Oracle implementation is the de facto standard.). .NET doesn't run only on Windows, Mono is project that exist for a while and it's use in many context. You can developer even application for Andriod phone in C#, because the language is open, you are welcome to make a compiler and re-use it everywhere!
So what if there is a 25% different in performance? Hardware is cheap. Software maintenance, administration, and licensing is expensive. The most compelling reason to use Java is that I can run it on Linux. That means I can clone VMs for development and testing, copy OS installations, and ship VMs to customers and resellers without having to spend time and money on licensing and activation. It makes development, testing, and deployment easier to automate when possible and hack when necessary for the small guys that don't have volume license agreements. .NET isn't the problem. Windows is.
Go green: turn off your refrigerator.
Open Office is slow as hell.
Repeat after me: Open Office is not written in Java, though it uses Java for some optional features. Yon don't even need Java installed to run Open Office, and disabling Java does reduce Open Office startup time since it no longer needs to start the JVM.
But it's a good meme to keep repeating, because when someone says 'Java sucks because Open Office is slow' and they're not talking about startup time, it's a very good indication that they have no clue.
If you think Reflection usage is bad in ASP.NET MVC, you've obviously never seen Spring...
Also, the "whatever Java has" above is "nothing" because the idiot tested a bare JSP running on Tomcat vs. a ASPX running on top of the entire MVC framework on top of IIS. Yeah, no wonder the perf is going to suck; that's a huge amount of completely wasted overhead. IIS can serve a dynamic ASPX page without any of that MVC garbage just fine, thank you... and with that, get rid of all the Reflection and so forth that, while actually useful in seriously enterprise-y organizations where you want to be able to do things like drop-in replacements of one class for another by changing a single line in a configuration file, are utterly wasted on a trivial benchmark like this.
There's no place I could be, since I've found Serenity...
Dude. Open Office is written in C++. It has some plug-ins written in java, but the main bloat is C++.
I was really expecting a "real" real world test.
I would like to see a head to head between, for example, WebLogic Server with Oracle DB vs. .NET IIS with SQL Server.
The test as is, IMHO, is crap.
I ran a similar test like this when I was having performance troubles with one of my QA apps.
I had written it in C# because I was bored and wanted to explore the language a little bit. I ran into issues with threading and performance when ramping up TCP connections and data processing.
I did a line-by-line rewrite into C++ (seriously, I copied the source and translated each line)....and all my performance problems went away.
In my experience, both Java and C# are easy to write, but abysmal when it comes to performance.
Good thing neither of the languages being discussed is in any way interpreted, or has been for a decade or so (actually, never in the official C#/.NET distribution).
But it's OK, I'm sure that somewhere under that mouth froth you actually know what you're talking about on some subject or other. Just keep searching, you'll find it eventually.
There's no place I could be, since I've found Serenity...
Um, no. You could probably write an entire office suite in perl and have it fit onto a few small pieces of paper when printed out; but nobody would ever understand it, probably not even the person who wrote it in the first place!
char*f="char*f=%c%s%c;main(){printf(f,34,f,34);}";main(){printf(f,34,f,34);}
While not very fair I've always tended to judge languages by their outcomes in terms of usability. From freeware utilities to products from large vendors, to websites using certain three letter extensions there have been certain recurring themes I have noticed throughout the years. Perhaps it is all expectation bias or a reflection of the culture of people who would use certain tools.. I won't pretend to know.
Is it fair to blaim PHP for SQL injection vulnerabilities found in PHP apps?
Is it fair to blame Java when an application outputs a stack trace and keeps on truckin as if nothing just happened?
Is it fair to blame Java when an application is as slow as a drunk snail or consumes mind boggling amounts of memory?
I think in the aggregate it might be possible to make the case for the quality of a programming language based on certain properties of a large sample of resulting programs.
What is the most interesting to me is the disconnect in effort spent by language designers to produce these modern languages and actual resulting outcomes. Why is ancient C(++) still soo popular and what gets used to write all of the core software? Why do we still have operating systems, network stacks and web browsers built in C when we have all of these superior languages with all of their holier than thou ivory tower labled features?
When is a _general purpose_ language going to come along that actually enables people to get amazing results which would not otherwise be feasible without the use of said language?
Who wouldn't cringe if they found out the latest version of their favorite browser had been rewritten in Java or .NET? In my view all TFA is doing is comparing the realitive intelligence of two mentally challenged competitors. I actually like both languages...NET somewhat more than Java. I just tend to not like the resulting program that comes out the other end.
I can't speak to C#. But I've written code for a financial exchange in Java with p50 response times around 100 microseconds. p99's are tricker but were still sub millisecond (mostly due to the GC, however we were moving toward zero GC's). Having said that, most developers who write Java would have balked at the unsavory things we had to do to achieve that speed.
I believe we undervalue the effect of the culture associated with languages. My experience is a lot of Java code is utter crap because the community is self reinforcing of bad ideas. I suspect that competent and motivated developers can take either Java or C# or C++ or whatever and make them fast.
I think in the end the system should have written the critical path in C as it has the right level of abstraction needed for low latency. Java or any other relatively high level language is great for supporting systems.
At which point, you have two choices: use a compiled language, or use an interpreted byte code language like Java or C#.
Neither Java nor C# are interpreted on heavy loads, they both JIT-compile, and they both have options (third-party) to compile to native code ahead of time.
The difference in performance between C++ and Java/C# has nothing to do with bytecode, and everything with their semantics. Their object model requires a GC - that's extra overhead. Their arrays are always bounds-checked - overhead. Class instances are always allocated on the heap (except for C# structs, which are rather limited in what they can do) - overhead. And so on.
They used to be mostly the same language, but that was somewhere circa 1.0. C# has developed much faster since then, and has a lot of things that have no direct equivalent in Java, like yield, lambdas, LINQ, dynamic or async/await.
Well gee, let's see. I can definitely say that C# programs do not perform as well on OSX, Linux, or IBM I.
Proverbs 21:19