Slashdot Mirror


Does C# Measure Up?

An anonymous reader queries: "Windows::Developer is offering a detailed, quantitative examination [free login required] of C#'s performance versus Java, C, C++ and D. 'Overall the results were surprising, although perhaps unexciting, in showing that C# (and to a less extent Java) is, to a good degree, on a par in efficiency terms with its older and (presumed to be) more efficient counterparts C and C++ at least as far as the basic language features compared in this analysis are concerned,' writes the author, Matthew Wilson. I'm only an amateur coder, and confess to not understanding most of the two-part article. I'd love to hear how true programmers view his results, which are too wide-ranging to summarize easily here. How about it Slashdot, as this special edition asks, 'Can C# keep up with compiled languages like C, C++, and D or byte-code based Java?'"

While we're on the topic of C#, rnd() queries: "It's been a while now, since Mono and DotGnu have begun eroding the market power of Microsoft by creating open source implementations of C# and the Common Language Runtime. Over the weekend I loaded Mono and did some informal benchmarking of object creation, intensive message passing, massive iteration, etc., and the results show that Mono is about 90% as fast as Microsoft's implementation after a very short time. I now want to switch my .NET development over to Linux/Mono exclusively, but I want to first settle on a free alternative to Visual Studio .NET 2003. Any suggestions?"

17 of 677 comments (clear)

  1. Re:jump off the bandwagon by trompete · · Score: 3, Interesting

    to add....

    GUI development isn't that bad in Visual Studio. In fact, it is easy as hell. With emulators like Wine available, it makes sense to develop the software with Visual Studio and its amazing debugging tools for WINDOWS and then use Wine to run it on Linux.

    One could use the GTK and GNU-C to develop multi-platform software in the first place, but then you are dealing with the parent poster's problem of debugging on multi-platforms, not to mention that GTK sucks under Windows (Anyone else use GAIM?)

  2. What's with all of the bellyaching about speed? by defile · · Score: 5, Interesting

    OK lets get a few things settled.

    Given: two identical applications; A, written in low level language like machine assembly, C, or C++; B, written in high level language like Java, Python, VB, hgluahalguha.

    If the application is high in CPU burn (lets call it X), like oh, for (i = 0; i

    If the application is copying a very large file using basic read/write system calls and large enough buffers (lets call this Y), A and B will have very similar performance.

    If the application is printing hello world, they will have similar performance, although the startup costs for B may be higher, and A will probably finish executing faster.

    MOST applications written today are written to solve for Y. The code that most programmers write today is NOT the CPU intensive portion. Usually the CPU intensive portion is in the library called by the programmer: rendering a box, moving things around on a storage device, making something appear on a network.

    In these cases, a high or low level language makes no freaking difference on execution speed. However, your choice WILL make a huge difference on time to develop, maintainability, resultant bugginess, SECURITY, etc.

    OF COURSE THERE ARE EXCEPTIONS. Maybe you're writing a routine that needs to draw lines fast, or move bytes through a network filter at 100MB/sec, or you're compressing a file, whatever. In these cases you tend to write the performance critical code in a more low level language so you have greater control over the physical machine. Sometimes you write the entire application in the low level language.

    Many high level languages provide mechanisms for calling low-level code when it's necessary for performance. It's often pretty easy.

    The performance argument is a red herring.

    1. Re:What's with all of the bellyaching about speed? by good-n-nappy · · Score: 4, Interesting

      Maybe you're writing a routine that needs to draw lines fast

      This is one of the specific things you can't really do with JNI and Java anymore. Java graphics is now really complicated. There's no way you'll be able to use low level OS rendering methods and have them integrate with Java2D and Swing.

      It's actually a real problem. You've got no recourse when the graphics primitive you need is too slow. You end up with a Java workaround or you switch to OpenGL or DirectX, which don't have good support for fonts and strokes and such.

      This is where C# may end up beating Java, on Windows at least. Eclipse SWT has promise too since you at least have the potential implement your own graphics code.

      --
      Never underestimate the power of fiber.
  3. Try it before you knock it by nissin · · Score: 3, Interesting
    I've programmed extensively in C and Java, with some C++. I took a typical anti-Microsoft stance early on and refused to even look at C#. I was finally convinced to try it, and I must say that it has some nice features.

    I recommend that any programmers out there try using it before discounting it. It might be especially interesting for those C++ programmers out there who don't like Java for one reason or another.

  4. Re:Languages are not application-neutral by Waffle+Iron · · Score: 4, Interesting
    Comparing C, C++, and C# is like comparing a wrench and a screw driver.

    Moreover, languages like C and C++ can be used in very different ways, depending on the circumstances. You can code the "safe convenient" way using tools like STL or glib to manage strings, containers, etc. I've found that the overall performance of such an application often is in the same ballpark of a Java implementation (other than Java's obnoxious startup time).

    However, C and C++ also allow you to write in a "masochistic balls-to-the-wall" mode that gives you much higher performance in exchange for 10X the programming effort. To do this, you often have to analyze your algorithms over and over until you can implement them using only stack and static structures. You avoid malloc() at all costs, avoid copying any data unless absolutely necessary, etc. You might disassemble the compiler output, run profilers and arrange data in cache-friendly patterns to squeeze out even more performance. The implementation will be much more brittle and prone to bugs, but you can often get a 10X or more speed improvement over the "natural" C or C++ implementation. Obviously, very few problems warrant this kind of attention, but making blanket statements about "comparing" other languages to C/C++ really should acknowlege the large range of performance that these languages can cover.

  5. ...and the .NET Framework is language-neutral by kylef · · Score: 5, Interesting
    What language you use depends on your application. Comparing C, C++, and C# is like comparing a wrench and a screw driver.

    And this is where the .NET Framework shines, because the CLR is a generic virtual machine to which any number of languages can be compiled. Currently there are C#, C++, VB, and even Java (under the moniker J#). There has been talk of writing a Python compiler and even possibly a Perl compiler. So you can choose your language of choice, and your resulting binaries or objects will fully interoperate with the other .NET languages and class libraries.

    And as far as this article is concerned, I think the interesting point is not that they're comparing apples to oranges, but just that the performance numbers for CLR-compiled C# aren't so horrible that they should scare off the majority of developers.

  6. #insert <obligatory_Java _generics_rant> by Anonymous+Brave+Guy · · Score: 4, Interesting
    Java SDK v1.5 (not yet released) contains support for 'generics', which are very much like C++ templates for Java:

    I really can't believe this thread. Why do people always come up with this worn out line whenever someone suggests that C++ templates are an advantage? And how come so many people have done so in replying to the same post? All but the first are (-1, Redundant), and the first is (-1, Ill-informed).

    OK, please, read this carefully, for I shall write it only once (in this thread):

    Java's generics are not even close to the power of C++ templates. They are glorified macros to fix a bug in the type system that should never have been there.

    C++ templates were at that level around a decade ago. Today, they're used not only to create generic containers (for which they are, no doubt, very useful) but also, via metaprogramming techniques, as the tool underlying most of the really powerful developments in C++ for the past few years: expression templates, high performance maths libraries, etc.

    If you didn't already know that, please read it again and understand it before proceeding.

    Java's generics don't even come close to the same power. They're a cheap knock-off, aimed at just one of the uses of C++ templates, which fixes a glaring flaw in the previous Java language. For that, they serve their purpose well, but please don't pretend they're anything more.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  7. Re:jump off the bandwagon by prowley · · Score: 3, Interesting
    I am not sure what server side applications you have been involved with but in my experience server side applications have LONG process lives. They are expected to be up 24 * 7, for as long as possible. Just as an example lets say Apache.
    Which just happens to not be written in Java... Server processes that do require to be up and running 24/7 are written in C (maybe C++) by people who know why. Servers written in Java for the 24/7 operation are written by people who read why in a magazine. Sorry, but I still cannot stifle a smile when Java and server are mentioned in the same sentence. I know there are many true-believers, but really, even if it does look good on paper, just wait til that garbage collector kicks in and I'll have yer 24/7 right here.
  8. Re:jump off the bandwagon by Anonymous+Brave+Guy · · Score: 3, Interesting

    Give or take a few quirks, most recent (last five years, say) C++ compilers support all the major features acceptably well for most purposes. There are only a few issues that cause significant problems: the infamous export, Koenig look-up and partial specialisation of templates come to mind. None of these features is used very often anyway, though.

    Coding standards that forbid the use of templates, exceptions and half the standard library in C++ are common, but way out of date.

    By the way, I write code for a living that gets shipped on more than a dozen different C++ platforms. Alas, some of them are well pre-standard, and so don't support even basic template or exception mechanics properly, which sucks. But this is an issue we've looked into in some detail, so I'm pretty confident in my statements above.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.
  9. Oracle by Un+pobre+guey · · Score: 3, Interesting
    So, with no loss of portability or functionality, you could do the same in C/C++.

    Try this:

    Write a backend app in Java, and one with the same functionality in C or C++. Make sure they both read and write data to an Oracle database. Now, with stopwatch in hand, make them both run on Win2K, Cygwin, Solaris, and Linux.

    Guess which language will allow you to finish first.

  10. Re:In Java's case ... by pyrrho · · Score: 4, Interesting

    but you have to remember that C++ is designed to open up the power of the machine to you, not make you think a particular way or be magical for you.

    The onus is on the "our language does it for you" crowd because you were not supposed to say "oh, you have to understand how the VM is working"... right?

    Of course, in the end, all languages will have to tell us this "oh, yes, well, you have to know something". Of course you do! It will always be this way.

    So choose the most efficient and effective language for you and learn it well, learn a different one if called for, etc.

    At least, I take this to be apparent.

    PS: "pyrrhonist"... right on!

    --

    -pyrrho

  11. Re:#insert by pyrrho · · Score: 3, Interesting

    I posted this already... go see how blitz++ works.

    It doesn't make the language butchered in the least, quite the opposite, the end result is very clear to use and the confusing part is hidden inside the classes, where it cannot cause trouble.

    the thing about C++ is, sometimes things are hard, but the reason you do them anyway is because they are worth it, and you can get high levels of abstraction (arbitrarilly high) without taking runtime hits. You have the ability to control your overhead, templates are a great example, especially the examples the parent poster mentions, expression templates, and high performance math libraries.

    Blitz++ uses templates in an elegant, mind blowingly cool way. It might not be clear how it works to many, but that doesn't change how it works. Truly beautiful. And it makes the code easier to read, not harder.

    --

    -pyrrho

  12. Re:jump off the bandwagon by deanj · · Score: 3, Interesting

    Start up time should be a lot better in the 1.4.2 release. Last JavaOne they specifically said work was being done on that. Further improvements are in 1.5 (when it comes out).

  13. Re:In Java's case ... by pyrrhonist · · Score: 3, Interesting
    but you have to remember that C++ is designed to open up the power of the machine to you, not make you think a particular way or be magical for you.

    I guess any language ends up indirectly making you think in a different way. Maybe that's the magical part.

    The onus is on the "our language does it for you" crowd because you were not supposed to say "oh, you have to understand how the VM is working"... right?

    Well, my point was that the languages are different in more ways than many C++ programmers (or Java programmers) realize. For instance, many C++ programmers think that finalize methods are destructors, and many of them use finalize incorrectly because of this. Then some of these programmers choose to complain loudly about Java, when the problem lies with them. They need to learn a new paradigm or their programs will continue to function incorrectly. There are definitely best practices in C++ that are bad ideas in Java.

    Obviously, this works in reverse, too. You can't go from Java to C++ without changing your thinking as well. Many Java programmers have made this mistake.

    Of course, in the end, all languages will have to tell us this "oh, yes, well, you have to know something". Of course you do! It will always be this way.
    So choose the most efficient and effective language for you and learn it well, learn a different one if called for, etc.

    Yeah, I agree. I use languages as a tool, not a crutch. If I see a problem that is better represented by Perl than Java, I'll use Perl. Or Python, or 6502 assembly...

    PS: "pyrrhonist"... right on!

    I like yours too. Pyrrho was cool.

    --
    Show me on the doll where his noodly appendage touched you.
  14. Bad Kool-Aid. by rjh · · Score: 4, Interesting

    Currently there are C#, C++, VB, and even Java

    If I understand the .NET framework correctly, there is no way to support either multiple inheritance or templates--in which case C++ cannot be accurately modeled in .NET. Nor will Java be .NETtable after 1.5, which will introduce pale imitations of templates (but imitation enough to give the CLR a hissyfit).

    The .NET CLR does not support multiple languages. It supports one language--C#. Its "multiple language support" comes from being able to compile down many functionally-identical languages with different syntaxes down to the same bytecodes.

    But truly different languages are not representable in the CLR. Show me how to do a Scheme continuation in the CLR, please, or export a C++ template, or a LISP macro.

    The only languages .NET supports are those which are subsets of C#. And once you realize that, .NET becomes much less interesting.

    (Warning: haven't used .NET much in the last few months. Last I checked these things were true, but after being very unimpressed with .NET I haven't kept up with things.)

    1. Re:Bad Kool-Aid. by gglaze · · Score: 3, Interesting

      How can this comment be (+5 Interesting) while each of the subsequent comments are 1's and 2's? When I first read this, I almost jumped to write a diatribe, and found that the other replies had already covered most of the important points very nicely. This comment should be marked (-1 : Ill-Informed) or some such rating, as it is highly misleading to anyone on /. who might be trying to learn about .NET.

      As the others have mentioned here, the CLR is an abstraction of the assembly instruction layer, not the "object-oriented" layer. Thus, a statement such as "CLR does not support {select archaic c++ OO concept}" does not make any sense. This obviously applies for things like multiple inheritance, templates, etc.

      Furthermore, the idea that the CLR "does not support multiple languages" is the most ridiculously malinformed statement I have ever heard about .NET, and trust me, I've heard plenty. One of the major objectives, if not the most important, is to bring to prime-time quality Microsoft's idea of supporting many languages on the same framework. They started this idea a long time ago with COM, and as it evolved, they realized all of the flaws in the COM architecture, and .NET is the next generation of multi-language support, in that sense. .NET currently supports what, like 20+ languages? Not all of them developed by MS, btw... Many of these languages use different paradigms (scripting-oriented, functional-oriented, procedural, etc.), and they all have access to the full breadth of the .NET framework. If that's not "multi-language support", I don't know what is.

      To assume that languages supported by .NET are "subsets of C#" is either naive or very malinformed. Anyone who knows the history of this knows that VB has always been Microsoft's baby, and C# is just the new kid on the block. Yes, now that C# has realized its potential, perhaps it is overtaking VB in popularity. But to claim that VB provides a "subset" of C#'s functionality is precisely backwards - in fact it is literally backwards - if anything, C# provides for the most part a subset of VB functionality, although technically the two provide somewhat intersecting but not fully overlapping sets of functionality - there are some things you can do in VB that you can't do in C#, and there are some you can do in C# that you can't do in VB. And the same goes for all languages on the .NET platform.

      Features like templates and multiple inheritance are first and foremost a feature of a language at the OO-level of abstraction - not the assembly level. As one poster noted here, Eiffel is a good example of a .NET language which already supports these concepts. If you wan't to complain that C# doesn't support them, that's ok. But to complain that "CLR doesn't support them" really doesn't make sense. Get your argument straight first.

  15. Re:-1: Ill-Informed by rjh · · Score: 3, Interesting

    First, I'll ask you to please see my comments in the other response to you...

    Done.

    In fact, even his "brilliant" graph algorithms may have been top-class during his time.

    As far as I can see, remember, or am concerned, Dijkstra's contributions to computational graph theory are fundamental to the field. If you think they're brilliant-in-quotation-marks, all I can ask is what you've discovered that's comparable.

    That's not meant as an insult or a challenge, incidentally. It's meant to say that in hindsight many things become obvious which required real genius to see them in the first place. Dijkstra's graph algorithms are simple and straightforward, and in hindsight they're obvious--but let's not forget that the only reason they're obvious to us is because Dijkstra had the insight to see, in foresight, what's obvious in hindsight.

    If in your academic mind you truly believe this,

    You keep on calling me that, an "academic". The reality is I'm nothing of the sort except in the sense that I'm a graduate student. I'm a hacker, not an ivory-tower academic. I believe in solving problems and sharing those solutions with the world.

    It's axiomatic that if you're faced with a problem, one of the worst things you can do is stubbornly insist that it be solved with X technique. You have to show some flexibility. You have to be able to approach the problem from different angles. For GUIs, I've found object orientation is almost always best. For scientific programming, I've found template metaprogramming best. For using computers in math theory courses, I use LISP or ML. For writing system-level software, I use C++. Etcetera.

    My insistence on multiple paradigms is unequivocally not born out of "academia", a word which it seems you're using as an insult. My insistence on multiple paradigms is born out of my demand that I use the right tool for the job. .NET claims it will support all programming languages. It doesn't. It doesn't even come close. Once you realize .NET is just another VM that can be more easily targeted by compilers, you realize that "hey, this is ... really ... not all that interesting or useful," as I said in the post which kicked all this off.

    Why is it not all that interesting or useful? Because we already have that with Java. We've got a virtual machine which provides managed services and is targeted by over 60 different languages, all of which can use all the facilities of the other languages once their code has been reduced down to bytecodes. We've got a VM which allows you to interface with the native hardware to get a massive speed boost.

    Am I talking about .NET or am I talking about Java? In this case, Java. (I can't confirm the 60+ languages bit, but that's the number I see. Last I heard, Java supported more languages than .NET, but this gap was rapidly closing and the numbers are a couple of months old.)

    So where is .NET interesting? It was interesting the first time Sun did it with Java. (Or, for us dinosaurs, it was interesting the first time I saw UCSD Pascal do it with their VM.) It's not interesting this second time around.

    Where is .NET useful? If you're married to the Microsoft platform, then I guess it's useful. But really, where's the huge win for .NET over Java? There isn't one. It's an alternative to Java, not really something new and innovative, not something which allows you to solve more problems than Java or even allows you to solve them all that much differently.

    That said, is it useful for Company A, which prefers VB, and Company B, which uses Java, to be able to collaborate on software, each using their preferred language, with their results able to be executed on a shared VM?

    Sure it is. That's not what I mean when I say ".NET is neither useful nor intere