Java Vs. C#: Which Performs Better In the 'Real World'? 437
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."
Language is hardly relevant (Score:5, Insightful)
They are both as good (Score:5, Insightful)
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.
Does it matter. (Score:5, Insightful)
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.
A question? (Score:4, Insightful)
I have seen it often said that when a slashdot headline ends in a question mark then the answer is no.
Re:Language is hardly relevant (Score:5, Insightful)
The reason this is interesting, is it's a very simple test, and hows the maximum performance. Requests can never be faster than returning a simple string. CLR + ISS is slower than JVM + Tomcat. Unfortunately, we don't know where exactly the performance difference lies.
These tests were also simple (Score:5, Insightful)
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.
Nothing to see here (Score:5, Insightful)
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
I don't like the premise. (Score:4, Insightful)
"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.
Re:Language is hardly relevant (Score:5, Insightful)
C# 5.0 (the latest version) has language-integrated async functionality that makes writing vertically scalable software a snap. It looks and behaves almost exactly like sync code, but actually runs async. Talking about server-side async here, not client-side.
Doing the same thing with Java or an older version of C#, where you have only the base libraries to help you, is really quite tedious to do properly.
So, for a test like this involving web development, I'd say language is actually a pretty relevant topic. Unless you've got lots of money to spend and can throw more hardware at something, the kind of perf improvement that can be provided by this is pretty astounding.
But, there are problems with this test. He says explicitly that he's looking for a real-world test, but then goes and basically times a Hello World. There is no database access, no concurrent users. No real-world anything.
Re:A question? (Score:4, Insightful)
Not just slashdot, but you're right: http://en.wikipedia.org/wiki/Betteridge's_law_of_headlines [wikipedia.org]
Re:Language is hardly relevant (Score:2, Insightful)
You've gotta be kidding.
Hey, I know of this great conspiracy site...
Comment removed (Score:5, Insightful)
Re:Language is hardly relevant (Score:5, Insightful)
The reason this is interesting, is it's a very simple test, and hows the maximum performance. Requests can never be faster than returning a simple string. CLR + ISS is slower than JVM + Tomcat. Unfortunately, we don't know where exactly the performance difference lies.
Nope, maybe that's what author think's he's doing, but he clearly doesn't understand the stacks.
For .NET, he's using the entire ASP.NET MVC framework to return a simple string. For Java, he's just using a bare servlet, and no framework code. To make this a fair test, he should be using Spring or something on the Java side.
Comment removed (Score:5, Insightful)
Re:Does it matter. (Score:5, Insightful)
Choosing a Language (Score:5, Insightful)
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.
Re:Language is hardly relevant (Score:5, Insightful)
Unless you're running Facebook or Twitter, the odds are that you don't really need to be asking questions like this. The bottlenecks you encounter are more likely to be poor code within your codebase than anything intrinsic about the language.
If you are running a site like Facebook that needs to scale beyond what that platform can realistically cope with, and your codebase is perfect and can't be made any faster, then it may be more feasible to do what Facebook did with PHP and fix the platform, rather than to switch to something different as that would involve rewriting your entire codebase, at which point you no longer have "perfect" code any more, and you lose the benefits of your dev team's existing skillset.
But very few of us are ever going to be in that position. Facebook did what the needed to do given the circumstances, but the rest of us should just concentrate on improving our own code before criticising the platform we're using.
Bottom line: If you write decent code, it doesn't matter what language it's in; all the major platforms are perfectly capable of running a high traffic web site. Conversely badly written code can and will bring even the most resiliant of servers to its knees. It's all about your code, not about the platform.
Anyone who tells you otherwise and says "language X isn't capable of doing that" is being a language snob. Feel free to ignore them.
Re:are they serious right now? (Score:5, Insightful)
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.
Re:These tests were also simple (Score:4, Insightful)
Frankly, the obvious problem (from somebody who has done a bit of both JSP and ASP.NET development) is the use of the MVC framework on IIS, and nothing even remotely equivalent on Java. If this were going to be as close to an apples-to-apples test as possible, you'd use bare ASP.NET (a single .ASPX page, possibly with a code-behind .cs file) and a single .JSP page.
I don't even think it's a matter of the author of the article having any agenda or something... I think he just honestly doesn't understand how to use the frameworks. For a very roughly analogous example from another programming domain, if I want to display a line of text on the terminal, I print a line of text. I don't go pull up the ncurses library and use it to create a one-line-tall TUI into which I create a label containing my text and then immediately exit. That would be... well, about as smart as using a heavyweight MVC framework to produce a web page containing the current time.
Re:They are both as good (Score:5, Insightful)
NetBeans does a better job of exposing the functionality you need, though the extensibility is more limited (like vi or nano).
Re:Language is hardly relevant (Score:4, Insightful)
This is Sun we're talking about, now Oracle; they were the original planet weird when it came to implementing programming languages. Swing is one of the few things I've seen leave programmers speechless with frustration.
Plus Oracle has been doing so well with their JREs that even DHS has recommended disabling their plugins lately.
Re:Language is hardly relevant (Score:2, Insightful)
Whoever still uses Java Applets in 2013 should have a very good explanation for his doings. We stopped using them 10 years ago.
I also fail to see how Java applets running in a web browser in any way relate to server-side code?
Swing actually has a quite nice API. I've seen worse. Of course it got a bad reputation after legions of hobby-grade developers failed to use threads for heavy lifting and instead did everything in the render thread.
I can write bad code in any language. There are many good reasons -a lot, actually- to not use Java client-side. Swing is not neccessarily one of them.
Re:Language is hardly relevant (Score:4, Insightful)
That and the fact that his "simple" test took longer to run than his supposedly more complex test in Java. Something wrong with the first test ? With the second?
Well, something very wrong with the overall test. When your results contradict themselves, you should not publish them.
Re:Aspects... (Score:4, Insightful)
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!
Re:Language is hardly relevant (Score:4, Insightful)
fast enough, for you, old man. (Score:2, Insightful)
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.
Re:Language is hardly relevant (Score:4, Insightful)
In the first test, he explicitly mentions going back on his word to use a Linux machine.
The author is clearly not a Java developer, and the second test really calls the first test into question. In the first test, he is having trouble with socket connections, which proved devastating to Java's numbers. Then, he moved onto using ASP.NET versus JSP in the second test, and JSP did significantly better than his simple socket tests in Java.
The simple fact that he did not go back to figure out what was wrong with his first test demonstrates quite clearly that both sets of his results are useless. It should be obvious that he is a weak Java developer--even without seeing the code--and I suspect he is not a particularly strong C# developer either on the basis that he did not question the results.
Duh. (Score:4, Insightful)
Well gee, let's see. I can definitely say that C# programs do not perform as well on OSX, Linux, or IBM I.
Re:Language is hardly relevant (Score:5, Insightful)
That's utter nonsense. In reality, Linux is no harder (and probably easier) to maintain than Windows: it's less complicated, its interfaces and tools change less over time, and there are numerous ready-made, turnkey server solutions that you basically just boot up and use. More CS grads will know and will have administered Linux systems than Windows systems because administration for Linux systems is much more similar between single user and multi-user.
School administrators may choose Windows because they believe it's easier to maintain, but they are mistaken.