Slashdot Mirror


C++ the Clear Winner In Google's Language Performance Tests

Paul Dubuc writes "Google has released a research paper (PDF) that suggests C++ is the best-performing language on the market. It's not for everyone, though. They write, '...it also required the most extensive tuning efforts, many of which were done at a level of sophistication that would not be available to the average programmer.'"

66 of 670 comments (clear)

  1. Common knowledge by PitaBred · · Score: 4, Insightful

    I thought this was common knowledge. Did anyone ever doubt that?

    1. Re:Common knowledge by Anonymous Coward · · Score: 5, Funny

      It's been common knowledge for at least a decade that Java is 6 months away from being quicker than c++.

    2. Re:Common knowledge by AuMatar · · Score: 5, Insightful

      There's a lot of Java-ites who claim that Java is just as fast. They're idiots, but they're vocal.

      --
      I still have more fans than freaks. WTF is wrong with you people?
    3. Re:Common knowledge by EvanED · · Score: 5, Informative

      A GC is a net loss, but don't think it doesn't have good effects mixed in there. Allocation of memory is a few instructions with a GC; malloc() can't hope to be in that same league. On a whole, GCs improve the memory locality of your program as it runs, with some substantial hiccups at the collections; manual memory management hinders it as your heap becomes more fragmented.

      On a whole I think most programs nowadays should be written in a managed language; the performance gap just doesn't matter for most things.

    4. Re:Common knowledge by Anonymous Coward · · Score: 2, Interesting

      Things are not so rosy on systems where RAM is scarce and/or there is no swap, as you can watch with the headaches of Android developers. On Android each allocation seems to take a chunk of your soul and the SDK comes with tools that help the programmer detect where they happen so they can avoid them. Most of the time pre-allocating chunks of memory yourself is more efficient than letting Android do it. So tell me, where is the advantage over malloc there?

    5. Re:Common knowledge by Rookitown · · Score: 2
      This paper was created with the sole purpose of getting accepted for an up coming Scala conference. Also, copied from my post on OSnews:

      This paper has some pretty serious issues as has been discussed extensively https://groups.google.com/forum/#!topic/golang-nuts/G8L4af-Q9WE and http://www.reddit.com/r/programming/comments/hqkwk/google_paper_com...
      For instance nearly all the optimization for the C++ code could have been applied to the Java code. Also according to Ian Lance Taylor:

      Despite the name, the "Go Pro" code was never intended to be an example of idiomatic or efficient Go. Robert asked me to take a look at his code and I hacked on it for an hour to make a little bit nicer. If I had realized that he was going to publish it externally I would have put a lot more time into making it nicer.

      I'm told that the program as compiled by 6g is significantly faster now than it was when Robert did his measurements.

      So yeah, in general a fairly floored benchmark, see the threads I linked for more details. I'm sure there's equivalent Java and Scala biased threads floating around as well!

    6. Re:Common knowledge by EvanED · · Score: 3, Funny

      Just for future reference, not everything I say is necessarily applicable in every situation. For instance, Java does not run very fast at all on my abacus. It would also be possible to craft some programs where the Java version would exhibit pathologically bad behavior and/or the C++ version would behave particularly well, and the consequences of GCs moving things around wouldn't be a big deal.

    7. Re:Common knowledge by MadKeithV · · Score: 3, Informative

      On a whole I think most programs nowadays should be written in a managed language; the performance gap just doesn't matter for most things.

      I've been developing professionally (disclaimer: in C++ ;-) ) for 10 years now, I've put up with people saying exactly this for 10 years, and for 10 years it hasn't been generally true at all.
      I don't mean to say managed languages have no place - I love using Python for scripting, and we've started doing GUI work in C#/.Net (oh no!) at my company as well, but there's always a dark performance corner where you end up having to go back to a language that gives you more low-level control. The performance gap doesn't matter in "some" things, but it matters at least once in every project I have worked on.
      More technically specific:

      malloc() can't hope to be in that same league

      So you write custom memory allocators for the specific cases that you need that perform better than malloc or indeed the generic allocator of any managed language. Note "allocators" - plural, we have more than one custom allocator for specific cases. I absolutely concur with Google though that this is "at a level of sophistication that would not be available to the average programmer.'"

    8. Re:Common knowledge by rvw · · Score: 2

      It's been common knowledge for at least a decade that Java is 6 months away from being quicker than c++.

      Just wait for Java++! Oh wait...

    9. Re:Common knowledge by martin-boundary · · Score: 3, Insightful

      It's reasonable to doubt that C++ is faster than ASM, and it's reasonable to doubt that C++ is faster than C. And if we're talking about hand tuned numerical libraries, it's reasonable to doubt that C++ is faster than FORTRAN.

    10. Re:Common knowledge by Pseudonym · · Score: 3, Interesting

      Why shouldn't a GC language where the GC has to search through lists regularly instead of you telling the memory management what to clean up by giving it the pointer be faster?

      When you're doing serious structure-hackery (as opposed to, say, string-hackery or numeric-hackery) in a non-GC language, you often end up having to structure your code around variable lifetimes, rather than structuring it around the algorithms like you're supposed to. The lack of GC can mean that some algorithms are not viable, and can result in the developer picking a worse algorithm instead. This kind of cost won't easily show up on a profile, but the cost is there, and it's nonzero.

      Compiler writers in particular know this, which is why even GCC uses GC. Yes, it's home-built application-specific carefully-applied-and-tuned GC, but it's GC nonetheless. I have a theory that one of the reasons why most languages use GC is that most languages are optimised for writing their own compiler in.

      Oh, and in a multi-threaded application, free() can be more expensive (in a latency sense) than malloc(). A well-tuned memory allocator maintains multiple arenas, so it can can allocate memory from whichever one has the lowest thread contention. But deallocating memory requires returning it to the arena from whence it came; you have no choice in this. Some high-performance applications (e.g. database servers) have been known to avoid the latency of free() by handing off critical memory blocks to a dedicated thread which just sits in a loop calling free(). Essentially, it's a GC thread, only it's a manual one.

      Don't get me wrong. I don't use Java for pretty much anything (definitely more of a C++-head). But one should never underestimate the cost of manual memory management, or of any other resource for that matter.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    11. Re:Common knowledge by EvanED · · Score: 2

      I sort of agree and sort of don't.

      The part where I agree is that I think that leaks can be overrated. Smart pointers take care of a lot of those problems, as you say, and even if they arise, they're often not a big deal. (So I restart my web browser every few days. It saves my tabs. Big whoop. Would be nice if I didn't have to do that, but that's not going to be what I base my "what software do I use" decisions on. 'couse for some high-availability web server, this would be disastrous.)

      The place where I disagree is when you look at other aspects of memory safety. When you look at all the stereotypical memory safety errors, they're often just about the hardest single-threaded bugs to track down. I diagnosed a use-after-free bug just a few days ago. I happened to get lucky and spotted it after 5 or 10 minutes because I happened to look at the right pointer values, but that was after a couple other people I think had spent many hours on it. And that's just talking bugs, not even getting into the whole class of security vulnerabilities that memory-safe languages eliminate.

      (Technically saying your language is memory-safe is different from saying it has a GC, but since memory safety is basically a prerequisite for having a decent garbage collector, in practice they go hand-in-hand. )

    12. Re:Common knowledge by SpazmodeusG · · Score: 2

      The allocation/deallocation advantages that GC languages have can be given to C++ through techniques such as memory pools.

      It's actually something seen on the all too common "hey this code is faster in Java than C++" examples that you see from time to time. They will be allocating and de-allocating many small objects. Without using a memory pool the C++ code will be slower whilst the Java program which internally uses a memory pool through its garbage collector will be faster. Of course, if you use a memory pool in C++ you get the benefits the GC language has.

      It's pretty much what this Google test shows. If you write C++ with optimisation techniques it will be quicker. There really isn't be any scenario where GC languages have a performance advantage unless you haven't optimised properly. After all the Java VMs that execute Java Bytecode such as Hotspot are themselves written in C or C++. You could simply copy their optimisation in your C++ code and be equal in the worst case.

      Whether or not the extra hassle of writing in optimised C++ rather than a garbage collected language is worth it is a different matter entirely though. I'm just pointing out that a GC language should never be faster than optimised C or C++. Google's test demonstrates that.

    13. Re:Common knowledge by Unoriginal_Nickname · · Score: 4, Insightful

      Boost/0x shared_ptr can't handle circular references.

      That's why people focus on memory management when they talk about C++: it's filled with 'gotchas' that will completely fuck you up if you don't completely understand everything you are doing. That's why so many C++ 'fans' hate automatic memory management. It's not because they're attached to the idea of manual memory management, it's because C++ forces you into a culture of paranoia and it's difficult to adjust to a world where the standard library isn't out to kill you.

    14. Re:Common knowledge by TheRaven64 · · Score: 4, Informative

      Compiler writers in particular know this, which is why even GCC uses GC. Yes, it's home-built application-specific carefully-applied-and-tuned GC, but it's GC nonetheless.

      No it isn't, it's just the Boehm GC with half a dozen small patches applied.

      Oh, and in a multi-threaded application, free() can be more expensive (in a latency sense) than malloc()

      Not really. Recent malloc() implementations use per-thread pools, so free() just returns the memory to the pool (so do most GCs). Multithreading is where you really start to see a big win for GC though. If you're careful with your data structure design, then you can just about use static analysis to work out the lifetime of objects in a single-threaded environment. When you start aliasing them among multiple threads, then it becomes a lot harder. You end up with objects staying around a lot longer than they are actually referenced, just to make sure that they are not freed while one thread still has access to them.

      It's also worth noting that most examples of manual memory management outperforming GC are, like most examples of hand-crafted asm outperforming a compiler, are quite small. If you can do whole-program analysis and write special cases for your algorithm, then you can almost certainly outperform general code, whether it's a compiler optimisation or a garbage collector[1]. If you try to do this over an entire program, then you're very lucky - most of us need to deal with libraries, and a lot of us are writing libraries so can't control what the people calling our code will be doing.

      As an anecdote, I recently implemented GC support in the GNUstep Objective-C runtime. I tested a few programs with it, and found that memory usage in normal operation dropped by 5-10%, with no noticeable performance change. The code inside the runtime was simplified in a few cases because it now uses the general GC rather than a specialised ad-hoc GC for a few data structures that need to have multiple critical-path readers and occasional writers.

      Some high-performance applications (e.g. database servers) have been known to avoid the latency of free() by handing off critical memory blocks to a dedicated thread which just sits in a loop calling free()

      This will cause a serious performance hit on modern malloc() implementations. The memory will be allocated from one thread's pool and then returned to another, meaning that almost every allocation in your 'performance critical' thread is going to require acquiring the global allocation lock. I'd be surprised if code using this pattern scaled to more than 4-8 cores.

      [1] Although, interestingly, Hans Boehm's team found that per-object allocator pools that most of the C++ advocates in this thread are suggesting have very poor performance compared to even a relatively simple GC. They tend to result in far more dead memory being kept by the program (reducing overall performance, by making swapping more likely) and, if implemented correctly, required much more synchronisation than a per-thread general allocator in multithreaded code.

      --
      I am TheRaven on Soylent News
    15. Re:Common knowledge by TheRaven64 · · Score: 2

      If you need speed, C++/C (well developed code and algorithms of course)

      And that's the clincher. Badly written Java is often faster than badly written C++, because the Java programmer just lets the VM do certain things while the C++ programmer writes their own slow and buggy version. And, on a big project, it only takes a little bit of bad code to offset the performance of the rest.

      --
      I am TheRaven on Soylent News
    16. Re:Common knowledge by HappyClown · · Score: 2

      Does throwing insults somehow might you right?

      You (and the mods who rated your comment "insightful") would do well to take an objective look at the facts here. If you'd bothered to RTFA, you'd realise that this is an apples to oranges comparison. The C++ code was optimised far beyond the Java code:

      "E. Java Tunings: Jeremy Manson brought the performance of Java on par with the original C++ version. This version is kept in the java_pro directory. Note that Jeremy deliberately refused to optimize the code further, many of the C++ optimizations would apply to the Java version as well."

      So while C++ might well be faster than Java, this article doesn't demonstrate that.

    17. Re:Common knowledge by ThePhilips · · Score: 2

      So, if memory management is issue today, something is wrong...

      Developers.

      Most CS courses went with GC-capable languages. Plus side: students can concentrate on algorithms and are shielded from even trivial details of computer architecture. Minus side: programming is all about resource management (resource being: CPU, memory block, file or even programs themselves) and new slew of developers are struggling with anything scaled from lab assignment to the real world magnitudes.

      Recently seen anguish of a developer who tried to open 100K files. And it didn't worked. And his perfect Java program failed and in process of doing so had corrupted some of the (precious) files already open. But he isn't guilty - really - it is poor design of OS or suckage of admins who put the limit in place.

      Memory management (or generally resource management) isn't the issue. It is that head of most developers nowadays are filled with long lists of useful libraries instead. People are slowly forgetting how stuff is working - and why it is working that way - they are more into linking some other code which already does it for them. Even if using the library encumbers more than helps. But I think we already had seen that trend occuring in CS before.

      --
      All hope abandon ye who enter here.
    18. Re:Common knowledge by Joce640k · · Score: 2

      I've been developing professionally (disclaimer: in C++ ;-) ) for 10 years now, I've put up with people saying exactly this for 10 years, and for 10 years it hasn't been generally true at all.

      Me too, and I really can't remember the last time I worried about memory management or had a memory leak in C++. It's just all automatic when you do it properly.

      The problem with GC is that they told people to use it for things other than RAM. For files, network connections, etc. GC is a very bad idea. You need those resources freed in a timely manner, not when some mindless robot thinks it might be worth doing.

      In Java there's no way to automate this process (no equivalent to C++ stack unwinding) so every time you use a non-RAM resource you have to type out a load of try ... finally blocks by hand.

      Oh, yeah, GC is sooooo much more easy/convenient. Not.

      --
      No sig today...
    19. Re:Common knowledge by __Reason__ · · Score: 2

      Compiler writers in particular know this, which is why even GCC uses GC. Yes, it's home-built application-specific carefully-applied-and-tuned GC, but it's GC nonetheless.

      No it isn't, it's just the Boehm GC with half a dozen small patches applied.

      Incorrect. GCC does not use Boehm GC. The boehm-gc you see in the GCC source tree is used by libjava, which is a java runtime library and unrelated to the compiler itself.

    20. Re:Common knowledge by dshk · · Score: 2

      Mod parent up. I have used shared_ptr ten years ago, and I also thought that C++ memory management is better, because I can tune it. But it is nowhere near to the power to GC. shared_ptr cannot deal with an object graph which has any circularity. It is the poor man's garbage collector. In theory you can optimize C++ better, in practice I have no need/time to optimize.

  2. Sensationalism at its finest by Toksyuryel · · Score: 4, Informative

    RTFA and take a good hard look at what they compared it to: Java, Scala, and Go. This post is a complete non-story.

    1. Re:Sensationalism at its finest by EvanED · · Score: 2

      If you did a lot of string manipulation, pascal would come out a lot faster. (because, for example, it knows the length of strings without having to crawl them looking for null bytes and such).

      I like Pascal strings as much as the next guy and think it's rather better than the C model, but it's not like you can't track lengths yourself and eliminate that performance difference.

      BTW, one subtle difference between C and C++ is in templates. Templates can reveal a lot more information to the compiler. The classic example here (which is probably an unusual case, but whatever) is std::sort in vs qsort from stdlib.h; std::sort typically blows qsort out of the water because it can do way more inlining.

    2. Re:Sensationalism at its finest by TheRaven64 · · Score: 2

      std::sort typically blows qsort out of the water because it can do way more inlining.

      You need to qualify that with 'in microbenchmarks'. In real code, the excessive special casing and inlining that C++ templates encourage causes program size to bloat hugely, which impacts instruction cache usage. An instruction cache miss costs 150+ cycles. A function call with working branch prediction costs half a dozen.

      --
      I am TheRaven on Soylent News
  3. ... and? by Durandal64 · · Score: 3, Informative

    Wow, they compared a whole four languages: C++, Java, Go and Scala, of which, C++ is the fastest. Is this seriously a surprise to anyone?

    1. Re:... and? by Morth · · Score: 2

      C would have been an interesting language to compare. We actually rewrote some C code to C++ and saw a speed benefit. Ofc, the original C code was very object oriented in this case, using structs with function pointers.

    2. Re:... and? by Canberra+Bob · · Score: 3, Interesting

      It would have been interesting to a C, C++ and Fortran shootout on some heavy number crunching. Throw in some OpenGL, OpenCL and assembly for good measure. We always get to see how high level languages compare, when in reality for most apps that are written in higher level languages raw speed is one of the lesser factors when choosing a language. Yet we never see shootouts between the lower level languages which would be used if speed truly was a concern.

    3. Re:... and? by Durandal64 · · Score: 2

      C? Compiled with clang? Or maybe more than one algorithm?

    4. Re:... and? by TheRaven64 · · Score: 3, Interesting

      It would have been interesting to a C, C++ and Fortran shootout on some heavy number crunching

      No it wouldn't. For this kind of algorithm, C, C++ and Fortran will generate the same compiler IR and you'll get exactly the same code out of the back end. The difference between compilers will be much greater than the difference between languages. Actually, it is already. For C, C++ and Fortran, EKOPath is 10-200% faster than GCC in real-world tests and synthetic benchmarks. There's more difference between GCC and EKOPath for C than there is between my Smalltalk compiler with Smalltalk and GCC with C, which is why language benchmarks are largely meaningless when you're talking about serial code.

      Language benchmarks are important when it comes to parallel code. For example, in Erlang I've written code that scaled up to 64 cores without even trying. In C/C++ I'd have to think very carefully about the design for that. Go is similar: it encourages you to write concurrent code. Idiomatic Go on a 64-processor machine would be a lot faster than idiomatic C++ on the same system, even if the C++ compiler did a lot more aggressive optimisation.

      --
      I am TheRaven on Soylent News
  4. C/C++ faster but produces more bugs by GoodnaGuy · · Score: 3, Interesting

    Yes its true that C/C++ is generally faster than other languages, but when it comes to writing bug proof code, its not so good. Its very easy to write past the end of arrays and use bad pointers amongst other things. From a career point of view, C/C++ is bad. I should know, my main expertise is in it and I am struggling to find a job. There seems to be way more jobs for Java and C# programmers.

    1. Re:C/C++ faster but produces more bugs by RotsiserMho · · Score: 2

      There may be more jobs, but in my (albeit limited) experience all the fun ones require C++ :)

    2. Re:C/C++ faster but produces more bugs by Erbo · · Score: 4, Insightful
      And, while C++ will always necessarily be faster to execute, there's no question that the other three languages will be faster and more straightforward to develop in. (Which, in general, makes them a net win, as programmer time is almost always more expensive than computer time, except in certain corner cases which should be obvious.)

      Why? Three words: Automatic memory management.

      No more worrying about whether you've allocated the right buffer size for your data...and maybe allocated too little resulting in an overrun screw, or allocated too much and wasted the memory. And no more forgetting to free that memory afterwards, resulting in a memory leak. You can write expressions like "f(g(x))" without having to worry about how the return value from "g" is going to be freed, allowing a more "natural" coding style for compound expressions.

      I maintain that automatic memory management, while not great for code-execution performance, is probably the single biggest boon to developer productivity since the full screen-mode text editor. (Not saying "emacs" or "vi" here. Take your pick.)

      Granted: You can retrofit a garbage-collecting memory manager onto C++...but that code will rob your C++ code of some of that enhanced execution performance which is probably the reason why you chose to develop in C++ in the first place.

      --
      Be who you are...and be it in style!
    3. Re:C/C++ faster but produces more bugs by smellotron · · Score: 3, Informative

      Yes its true that C/C++ is generally faster than other languages, but when it comes to writing bug proof code, its not so good.

      Well when you put it that way, it's not a surprise. C and C++ are different languages with different approaches for effectively achieving low error rates. If you approach them as a single "C/C++" language, you'll end up inheriting the weaknesses of both languages without likewise inheriting the strengths of either.

    4. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 2, Interesting

      Seriously, everybody using heap directly in C++ should reconsider his coding practice. Memory management, automatic or manual, is something that should never be exposed at interface level. And, unlike Java, in C++ you can actually achieve this.

      Good code in C++ is simply not using heap, except perhaps for some low-level implementation stuff. If you are concerned about buffer overruns or 'delete' responsibility, you are not using C++ correctly. In my C++ code, I have hardly one new/delete per 10K lines of code (with total codebase maintained about 500K lines)

    5. Re:C/C++ faster but produces more bugs by Vintermann · · Score: 3, Insightful

      So, you never have any memory leaks? Or double frees? Convenient for you that you're an anonymous coward, because it would probably be a quick issue to call you on. I've met some extremely careful coders (among other things, the developer of one of the first projects to reach zero defects in Coverity's open source scan effort), and none of them make such ridiculous statements.

      --
      xkcd is not in the sudoers file. This incident will be reported.
    6. Re:C/C++ faster but produces more bugs by SerpentMage · · Score: 2, Informative

      Your C# example is BS. What you are referring to is when you want the resource to be cleaned up. C# will clean up the resource, but the question is when. Using the using keyword means an explicit IDisposable interface is called when the object goes out of context. Otherwise it is called when the object is garbage collected.

      --

      "You can't make a race horse of a pig"
      "No," said Samuel, "but you can make very fast pig"
    7. Re:C/C++ faster but produces more bugs by fyngyrz · · Score: 2

      Yes its true that C/C++ is generally faster than other languages, but when it comes to writing bug proof code, its not so good.

      No, you mean YOU aren't so good. A good c programmer won't produce any more bugs than a good any-other-language programmer; we know how to handle memory, multi-threading, and those other issues that terrify those who have only worked with languages with training wheels permanently attached.

      --
      I've fallen off your lawn, and I can't get up.
    8. Re:C/C++ faster but produces more bugs by Stele · · Score: 2

      That you got 5 Insightful indicates that most people are quite ignorant of many of C++'s features.

      It's very easy to have "automatic memory management" in C++ without resorting to GC. STL containers and reference-counted smart pointers make this trivial. I have written numerous commercial applications in C++ and most of them do not have a single explicit "delete" or "free" statement. And I get templates, which lets the optimizer do some amazing things.

  5. Language shoot-out confirmed by istartedi · · Score: 3, Informative

    This jibes with "common sense" and the computer-language shoot-out

    It's not useless. It's nice to see multiple studies with different approaches coming to the same conclusions.

    --
    For all intensive purposes, "whom" is no longer a word. That begs the question, "who cares"?
  6. basic by theheadlessrabbit · · Score: 4, Funny

    They didn't test BASIC? Lame...

    --
    -I only code in BASIC.-
  7. What? No FORTRAN?? by paulatz · · Score: 2

    I'm disappointed, everybody knows that when the going get tough FORTRAN get going

    --
    this post contain no useful information, no need to mod it down
  8. Re:Google = Captain Obvious by SpryGuy · · Score: 2

    The fact that they left out C# seems odd as well. It makes me wonder what the point was, really.

    --

    - Spryguy
    There are three kinds of people in this world: those that can count and those that can't
  9. Environment, conditions and parameters by meburke · · Score: 3, Interesting

    Notice one of the comments pointed out that Borland Pascal was one of the fastest executing languages next to ASM. I remember that Borland Pascal (in 19991) executed almost 10 times faster than Borland C++ on a consistent basis on the same systems.

    This only points out that tests need to compare apples and apples. I would be quite surprised if any C++ can execute a FFT as fast as my Leahy FORTRAN95.

    If I was going to pick only one language to work with, it would probably be LISP, but Haskell comes a very close second. I like code that does exactly what I want it to do with no side effects.

    There is much more to comparing languages than is reported in the article, including testing the language's suitability for a given task.

    --
    "The mind works quicker than you think!"
    1. Re:Environment, conditions and parameters by Daniel+Dvorkin · · Score: 5, Funny

      I remember that Borland Pascal (in 19991) executed almost 10 times faster than Borland C++ on a consistent basis on the same systems.

      Apparently, the reason it executed so fast was because it was reaching 18000 years into the future to run on the computers of the galaxy-spanning civilization built by the hyperspatial god-beings who will be our distant descendants. Man, Borland had some great tech in its day.

      --
      The correlation between ignorance of statistics and using "correlation is not causation" as an argument is close to 1.
  10. Assembly by Baby+Duck · · Score: 3, Interesting

    If pure speed is the sole criterion with tuning effort having zero consideration, wouldn't masterful Assembly or opcode be the fastest?

    --

    "Love heals scars love left." -- Henry Rollins

    1. Re:Assembly by MachDelta · · Score: 3, Funny

      A prof of mine used to say that "writing a program in assembly is like writing a novel in math."

      Anything longer than a haiku and you''ll want to blow your brains out.

    2. Re:Assembly by should_be_linear · · Score: 2

      No, I learned programming in assembler (Zilog Z80), and used asm (MC68000, 8086-386, ARM) often until maybe 1995 when I realized that modern C/C++ compilers are generating faster code then I was able to write in asm by some 20%. For "ordinary" programs this is the case until today, more so with increasing quality of compilers. Exception is some small specialized functions, like inner loop of video encoder, where you can use SSE still better then compiler.

      --
      839*929
  11. Re:Google = Captain Obvious by Daniel+Dvorkin · · Score: 2

    In the absence of evidence to the contrary, it's reasonable to assume that C#'s performance results would be about the same as Java's. Testing C vs. C++ vs. Fortran would much more interesting. (There is no such language as "C/C++" and it's really irritating when people lump them together, as many commenters on this story have.)

    --
    The correlation between ignorance of statistics and using "correlation is not causation" as an argument is close to 1.
  12. Java is fast by wurp · · Score: 4, Insightful

    In some situations Java will be faster than unoptimized C++ - JIT compilation will do enough of a better job than vanilla C++ to make the difference. In general, C++ will clearly be faster. However, I think what most of the people you're qualifying as idiots get up in arms about (rightly) is the assumption that so many programmers seem to make that Java will be many times slower than C++. That's (usually) just wrong.

    In particular, here's what Google's analysis had to say about it on page 9:

    Jeremy Manson brought the performance of Java on par with the original C++ implementation

    They go further to say that they deliberately chose not to optimize the Java further, but several of the other C++ optimizations would have applied to Java.

    For most programming tasks, use the language that produces testable, maintainable code, and which is a good fit for the kind of problem you're solving. If it performs badly (unlikely on modern machines), profile it and optimize the critical sections. If you have to, write the most critical sections in C or assembly.

    If you're choosing the language to write your app based on how it performs, you are likely the one making bad technical decisions.

    1. Re:Java is fast by Splab · · Score: 4, Insightful

      For me it doesn't matter which language is faster, I'm using the one that solves my problem the fastest (e.g. shippable product fastest) and right now, Java is the main player for me.

      Also, since our CPUs aren't getting any faster, we need to use languages that makes threading easier the safest way and on that topic, Java is miles ahead of C++. (Java used to have an utterly broken threading model, but these days it works [tm]).

    2. Re:Java is fast by johanatan · · Score: 2

      C++0x (or whatever they call it these days) adds 'threading'. And, if you really want parallel, efficient, compiled code, go for Haskell.

    3. Re:Java is fast by sim82 · · Score: 2

      Jeremy Manson brought the performance of Java on par with the original C++ implementation

      essentially they say that you need some kind of expert to produce java code that is on par with "straight forward c++". This corresponds somehow to my own experience (java can be fast, if you put in the effort). On the downside, you need some kind of expert to create normal (=good) c++ code in the first place...

  13. piss n vinegar by Phantom+of+the+Opera · · Score: 2

    Of course its going to be a C that wins. It's pushed close to the iron. C++ is for the careful, exacting personalities. I simply don't have the patience to use it on a day to day basis. Scripting is for the frenetic like me. If you pick a scripting language, you're selling out performance for keeping your rapid development and sanity. You can write beautiful safe stuff in C++ too. Use what you're comfortable with.

  14. Average Programmers... by sparky1240 · · Score: 2

    '...it also required the most extensive tuning efforts, many of which were done at a level of sophistication that would not be available to the average programmer.' I think that's the problem in a lot of systems today. Too many "average" programs are being written by too many "average programmers" - and this is why there are the problems such as memory leaks, etc. I feel too many have been spoilt by the ridiculous memory and processing speeds available in todays computers. What ever happend to understanding how functions perform and refining code to be lean and mean?

  15. Nope - Java refused to go in to the ring by sgt101 · · Score: 2

    From the paper (section 6,E: Java Tunings) ". Note that Jeremy deliberately refused
    to optimize the code further, many of the C++ optimizations
    would apply to the Java version as well.'

    --
    --------------------------------------------- "In the end, we're all just water and old stars."
  16. C++ is like sex in high school... by Anonymous Coward · · Score: 2, Insightful

    ... most people are doing it wrong.

    Good use of C++ fills a very small niche of people that want a relatively high-level language but care about a statement like "the compiler generates good code for this"... You want some of the properties of C, like being close to the hardware and generating straightforward machine code. Add to that some things that make OO easier. Add type safety. Add templates and function objects, which due to inlining gives you much better machine code than the typical C approach of a function pointer and a void* to provide such extensibility. What you have is kind of like "a better C". It has a lot of quirks and baggage, but with the proper understanding of the good and the bad it's really good for the sort of niche where these choices make sense.

    The problem I have encountered is that bad C++ programmers are a dime a dozen. I don't think I've ever had any co-workers who would understand my previous paragraph. I know from reading books and papers and Internet that people who "get" C++ exist. The best I can say is that the vast majority of people using a C++ compiler don't know what they are doing. Instead I've met a lot of people writing C++ code who probably should be writing in Java anyway; they discard most of what C++ is good for, usually because they don't really understand it and they're trying to write Java-ish code in C++. The results aren't pretty.

    In a way I agree with what Linus said in one of his famous emails, where some silly person was suggesting to rewrite git in C++. To paraphrase: Choosing C as a language is good even if the only thing it accomplishes is it keeps out the bad C++ programmers.

    I guess the silver lining is that no two people can agree on what "good" C++ is. So maybe I'm just being too harsh in my assessment.

  17. Not a language shootout.... by antifoidulus · · Score: 3, Insightful

    There is no such thing as a real "computer language speed test", this is really a test of compilers, environments, VMs/interpreters, and environments. The first question that has to be raised is of course when the program is running on hardware, what "language" is it written in? The hardware sure doesn't give a shit. You can compile almost any language into native code, including VM driven languages such as Java and PERL. Now granted TFA states that they ran their loop 15k times to try to minimize the effect of the load time and run as much JIT compiled code as possible, but that's still not the same as compiling it directly into native code.

    Which brings up another point, are they really testing the "programming language"(which is just a bunch of specification and usually implementation hints) or are they testing the compiler/environment they are on. Code compiled with GCC and ran on a Linux box will probably perform differently than code compiled with Microsoft's compiler running on Windows which will behave differently than code compiled with LLVM/CLanger running on OS X...... You can probably say the same thing about Java compilers, I'm assuming they used the Oracle reference javac, but there are other Java compilers out there. How do you test the speed of the "language" when so much of that performance depends on the compiler and environment you are running other?

    Which leads into my final point, when does a language stop becoming something written in that language? Although not tested this time, probably the best example of this point is Ada. Anyone who has coded in Ada knows how insanely strict it can be, it constantly does things like bounds checking to ensure that data stored in subtypes is within the bounds of those types. However on most Ada compilers most of these checks can be disabled with just a couple compiler flags. Obviously the resulting code is going to be faster than if you kept the checks in, but does it stop becoming Ada at that point? You can make a similar case for Java and JNI. JNI is completely legal in the Java language specification, but when you use JNI does your program stop being a Java program? Could you have optimized it further by using JNI?

    This is merely a test of whatever compilers/VMs they used in whatever environment they ran the code in, nothing more, nothing less.

  18. Also by Sycraft-fu · · Score: 3, Interesting

    It often turns out programmers are not as good at the assembly as they might think. I'm not saying a little hand tuned assembly isn't useful for some things but the "I can do better than a compiler," attitude usually has no basis in reality. Good ones are pretty clever at optimizing things. So maybe if you have an area of your code that uses a lot of time (as determined by a profiler, don't think you are good at identifying it yourself) and write a hand tuned in-line assembly version (maybe starting with the assembly the compiler generates). However you don't go and write the whole program in assembly.

    C++, of course, is something you can quite easily write a very large program in, or operating system for that matter. Not quite as easy as a fully managed language, but perfectly feasible to deal with large scale and indeed it is what a large number of projects use.

  19. I don't know about that by Sycraft-fu · · Score: 2, Funny

    Talk to Java heads they'll tell you Java is already faster than C++. They can show you some contrived tests to demonstrate this too! Of course they never seem to have a good answer for why if this is the case all performance important apps (like games, audio software, etc) are written in something else or why Java linpack pulls like 750Mflops on a system where native compiled (from C) Linpack gets 41Gflops. However they are sure it is faster!

    1. Re:I don't know about that by mario_grgic · · Score: 4, Interesting

      That's because Java floats are not the same as C floats so compiler can't use the CPU's FPU to do the work for it directly. Java float types make more wider guarantees than C floats (that are usually just restricted to underlying hardware float). This is exactly the reason why Fortran beats C or C++ when it comes to numerical computation. The Fortran compiler can output faster code because language makes some guarantees and it's easier/possible to optimize it better.

      --
      As the island of our knowledge grows, so does the shore of our ignorance.
    2. Re:I don't know about that by serviscope_minor · · Score: 2

      This is exactly the reason why Fortran beats C or C++ when it comes to numerical computation.

      Those are different guarantees. Fortran provides some better floating point facilities for numerics, like errors on a loss of precision, but those don't affect speed on common hardware. The main thing about FORTRAN is that the lack of array aliasing and pointers makes optimization much easier. C now has the restrict keyword which gives you similar options for optimization.

      --
      SJW n. One who posts facts.
    3. Re:I don't know about that by w_dragon · · Score: 2

      This is also true of integer types - Java guarantees a long is 64-bits. C++, well, on a 32-bit machine a long will be 32 bits with any compiler I'm aware of. On 64 bit Windows a long remains 32 bits. On 64 bit Linux a long is 64 bits. Makes Java easier to write in, but if you try to run it on a 32-bit machine you'll take a performance hit if you're using a long where an int would do.

    4. Re:I don't know about that by rjstanford · · Score: 4, Informative

      Talk to Java heads they'll tell you Java is already faster than C++. They can show you some contrived tests to demonstrate this too!

      Take a look at the comments on http://jeremymanson.blogspot.com/2011/06/scala-java-shootout.html about the paper:

      Here's one from the top:

      The benchmark did not use Java collections effectively. It was generating millions of unnecessary objects per second, and the runtime was swamped by GC overhead. In addition to the collections-related fixes I made (as described in the paper), the benchmark also used a HashMap when it should have just stored a primitive int in Type; it also used a LinkedList where it should have used an ArrayDeque. In fact, after being pressed on the matter by other Googlers (and seeing the response the C++ version got), I did make these changes to the benchmark, which brought the numbers down by another factor of 2-3x. The mail I sent Robert about it got lost in the shuffle (he's a busy guy), but he later said he would update the web site.

      Changes which, I might add, are still far easier for the average Java peon-on-the-street to understand than the C++ equivalents. The fact that the paper was comparing one program in C++ that had been optimized to within an inch of its life with another program, in Java, that had had someone spend about an hour "cleaning it up a little," makes for a grossly unfair comparison.

      The fact that the "naive" (far more common) programs were all relatively the same speed was insightful.

      --
      You're special forces then? That's great! I just love your olympics!
    5. Re:I don't know about that by rjstanford · · Score: 3, Informative

      BTW, a little extra digging reveals that the code was written by a C/C++ compiler writer who's a novice developer in Java/Scala. I'd say that the fact he did so well, comparatively speaking, in Java and Scala would be more noteworthy than the current takeaway.

      --
      You're special forces then? That's great! I just love your olympics!
  20. Re:Says who our CPUs aren't getting faster? by Splab · · Score: 2

    2-3Ghz Cpus have been out for ages, they are so fast, signals can't travel any meaningful distance within a single cycle - it makes a lot more sense to core up than to try and beat the speed of light. And you pointing out a core clock from 700 to 1Ghz in 3 years is good is actually just proving my point. 8-10 years ago you would expect a double up every 18 months, it's just not economically and physically viable to keep that race going.

    And yes, they might have new instructions and they might be doing more per clock cycle, but you are by no means anywhere near the double up in efficiency *per* core that we used to see. The future is threaded applications - if you can't thread, go find yourself a nice FPGA.

    Also, at no point did I *EVER* say you can't thread in C++ (please read peoples post and if you do, please don't put words in their mouth) - threading, and more importantly locking is vastly easier and safer to do in Java than C++.

    Sure, if you write embedded applications, Java *might* not be the best option for you, but there are loads of processors that can handle Java in embedded settings - if what you are doing is something where microseconds matter, Java isn't your cup of tea, but for 90%+ of applications out there Java would be fast enough.

  21. Re:Business is different by serviscope_minor · · Score: 3, Insightful

    It's really painful to write C/C++ code

    That's because if you treat C and C++ as one language, then you suck as a C++ programmer.

    --
    SJW n. One who posts facts.