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.'"

670 comments

  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 drolli · · Score: 1

      Oh yes. 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?

      The magic of the buzzwords creates a reality distortion field around the code.

      (I like java, but i know how to profile code.).

    4. 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.

    5. 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?

    6. 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!

    7. Re:Common knowledge by rottenSoul · · Score: 1

      google are fairly unique in having a single feature to polish over many years. Most of us in the dev world dont have the luxury of time to polish usecs from a call.

    8. 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.

    9. 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.'"

    10. Re:Common knowledge by Anonymous Coward · · Score: 0

      I develop almost all of my scientific simulation software using Java but I feel sick when someone claims Java is/can be as fast as C/C++.

      Java is used for simplicity and ease of development not because of its speed. If you need speed, C++/C (well developed code and algorithms of course) is the way, at least with existing options.

      I have done many experiments to confirm that (all versions of java) and I won't continue to do hat forever.

    11. Re:Common knowledge by drolli · · Score: 1

      Yes i also prefer gc languages, but the task in the article was very specific.

      I would even say that if you have such a very specific task, you write (or custiomize) your own malloc (not unusual when doing numerics) to prevent thing like heap fragmentation. (on the other hand, one could write a specific gc...)

    12. Re:Common knowledge by beelsebob · · Score: 1

      More importantly... Did anyone ever care about that? I spend my days writing computer game engines, and I don't remember the last time I worried about the performance of a language.

    13. Re:Common knowledge by Anonymous Coward · · Score: 0

      I really think GCs are overrated. Honestly, in C++ you don't even deal with memory management that often. And if you do, it's encapsulated in an object. You're also able to allocate on the stack a lot more in C++ than in, say, C; and with things like scoped_ptr, shared_ptr, etc, the memory management really becomes trivial. Not to mention the fact that your code will run with predictable response times, unlike long-running Java code when the GC sweep kicks in.

      There are many other aspects of C++ that are far more painful than memory management, so I'm not sure why the focus always seems to lie there.

    14. 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...

    15. 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.

    16. 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});
    17. Re:Common knowledge by d4fseeker · · Score: 1

      So that's the reason why some indie game eat more CPU than better-looking multimillion$ budget titles.

    18. Re:Common knowledge by DMiax · · Score: 1

      I see alternating results: http://eigen.tuxfamily.org/index.php?title=Benchmark Let's see it again in a couple of years and the result may be one sided. I hate C++ with a passion, but only because I avoid writing in FORTRAN at all.

    19. 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. )

    20. Re:Common knowledge by Unoriginal_Nickname · · Score: 0

      What do you think malloc does? The C heap is a linked list. Libc has to do a worst-case Theta(n) search on a linked list for free space on allocation. Depending on your implementation, it may even wait until an allocation fails before it compacts the heap - causing a several second or minute pause in the middle of a malloc call.

      If you haven't written software big enough to see the disadvantages of malloc, you haven't written software big enough that you should care about the cost of a GC.

    21. Re:Common knowledge by Bert64 · · Score: 1

      Manual memory management doesn't necessarily result in fragmentation, it just leaves the job of avoiding fragmentation in your hands.

      --
      http://spamdecoy.net - free throwaway anonymous email - avoid spam!
    22. Re:Common knowledge by martin-boundary · · Score: 1

      Nice! It would be interesting to see those same benchmarks compiled with Intel's compiler suite (for comparison).

    23. 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.

    24. Re:Common knowledge by Anonymous Coward · · Score: 0

      Your colleagues must be lame, valgrind would have found such errors in 5 or 10 seconds.

    25. Re:Common knowledge by EvanED · · Score: 1

      "On the whole."

      And there are programs & inputs where you won't be able to avoid fragmentation short of relocating existing objects and fixing up pointers (i.e. what a copying GC does anyway).

    26. Re:Common knowledge by EvanED · · Score: 1

      Part of our code base is Windows-only; that was part of it. (Fortunately this is becoming less of an issue.)

      We've made an attempt at using Purify on Windows but that didn't go very well... I forget what the issue was.

    27. Re:Common knowledge by N+Monkey · · Score: 1

      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,

      Have you used Electric Fence or Valgrind?

    28. Re:Common knowledge by drolli · · Score: 1

      If your programming course did not tech you to take care about the different mallocs out there, i feel sorry for you.

      If you assume that structure complexity has something to do with code complexity, i feel sorry for your boss. There are extremely simple programs which show you the dangers of malloc. I would go so far to say *especially* simple programs may see a significant time in malloc because it may be that a significant part of managing the data structues is done in malloc.

      If you assume that generic solutions (gcc uses a....) to specific problems must always be the same, i feel sorry for your customers.

      Its very funny that i was specifically referring to freeing memory, and that you refer to a *specific* implementation of malloc while *not* comparing it to the way in which *allocation* works in other languages.

      Finding a free memory area to put a structure in should not be a very different task for a gc-managed memory list than for a malloced memory list. In the gc case you can hide the "compaction" in the gc cycle somewhere (which may be the right thing to do for most applications).

    29. Re:Common knowledge by EvanED · · Score: 1

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

      If you know the sizes of the objects you'll be allocating in advance (you don't always) and the library you're using allows it, and if a few other things work out. As it so happens this often is the case, but it isn't always.

      I'm just pointing out that a GC language should never be faster than optimised C or C++. Google's test demonstrates that.

      Sure, but that's somewhat of a given in the sense that you can make C "fake" everything that Java does behind the scenes. If you found some situation where Java's JIT was giving a performance boost, you could go and write a JIT and JIT your C code.

    30. Re:Common knowledge by EvanED · · Score: 1

      They other problem was that something set them off on a wrong trail, so they weren't even looking for a memory corruption bug. If they had Valgrind available, I'm not sure they would have used it.

    31. Re:Common knowledge by EvanED · · Score: 1

      See this reply (and my followup).

    32. 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.

    33. Re:Common knowledge by Anonymous Coward · · Score: 0

      Grand-parent works for Hunted Cow Studios Ltd doing iPhone game development?

    34. Re:Common knowledge by headkase · · Score: 1

      You know "fake" isn't the right word. You can implement everything you happen to need from a higher-level language into an expressive lower-level one. That is not always possible the other way around.

      --
      Shh.
    35. Re:Common knowledge by N+Monkey · · Score: 1

      I think there is an electric fence equivalent on Windows- it might be called something like bounds checker - if that's any help.

    36. Re:Common knowledge by AmiMoJo · · Score: 1

      A compiler level GC for memory management is quite different to the GC used in OO languages though.

      As for latency a significant amount is down to the need to wipe memory between use. IIRC it comes from POSIX originally, the idea being that each program's data is cleared to prevent other programs from reading it when the memory is re-allocated. If you allocate 1MB of memory at some point the OS has to clear it which means a nice big CPU loop.

      --
      const int one = 65536; (Silvermoon, Texture.cs)
      SJW, n: "Someone I don't like, and by the way I'm a fuckwit" - AC
    37. Re:Common knowledge by Dails · · Score: 1

      Oh, of course. I write games myself for recreation, and while there are still substantial technical differences in indie and AAA games (there are some really, really smart people working on AAA games coming up with really clever programming techniques), the primary difference is level of effort. If you have the money to pay a lot of artists and programmers to hack on something for 8+ hours a day for two years, you're going to get an amazing product. With three(ish) guys working on something for two hours a day for however long they maintain interest, you'll probably get a fun game that you would have paid $30 for 10 years ago.

    38. Re:Common knowledge by Unoriginal_Nickname · · Score: 1

      I didn't compare it to alternatives because that isn't the point of my post. The point is that C and C++ programs must* also "search through lists regularly" during memory management, which obviates whatever complaint against garbage collection you were trying to make. No offense, but you really don't come off as understanding this problem as well as you want to.

      (*or trade it for, I think, Theta(2^k) extra memory, where k is the number of bits in the largest block that can be allocated. If that sounds wise.)

      I've never taken a "programming course." It sounds ghastly.

    39. Re:Common knowledge by drolli · · Score: 1

      Which part of my comment did make you feel i do not understand that *allocating* memory involves searching trough a list? Why *exactly* did you think i pronounced that? And could you explain how a garbage collector can help me *find* free memory faster?

    40. Re:Common knowledge by larppaxyz · · Score: 1

      It's been almost 10 years since i last time made anything useful with C++ and i don't really have any experience with Java. This thread still makes me wonder how can it be that memory management is an issue of any kind? Back in 90's it was not problem at all to create custom memory management class that would take care of freeing resources and even fragmentation. With Amiga and no MMU my memory management system also had simple buffer under-/overflow checking. And hey, didn't Doom 1 also have memory management (and cache) of it's own...?

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

    41. Re:Common knowledge by DMFNR · · Score: 0

      Sure you can! You just have to write a C compiler in the higher level language!

    42. 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
    43. Re:Common knowledge by TheRaven64 · · Score: 1

      The C heap is a linked list

      There's a reason it's called a heap, and it's not because the data structure used is a linked list. Actually, it's not a heap anymore either, it's usually something a bit more complex.

      --
      I am TheRaven on Soylent News
    44. Re:Common knowledge by mapkinase · · Score: 1

      The faster the progress, the more volatile the market, the faster the rotation of the products, the more importance is to faster development cycles. Test languages for that, Google.

      Take science. In the beginning it was FORTRAN for physicists, which was optimized for performance in scientific calculations.

      After that with the emergence of biological science and them beating physics as the most important, emergence of bioinformatics employed PERL as the major language. At that time C and C++ were already established languages, so why bioinformaticians chose PERL?

      Because PERL provided an opportunity for (a) fast development of bioinformatics tools by (b) biologists without any training in computer sciences.

      C++ just did not cut the deal with it's anal data type checking and wordy GetThisMember() and SetThatMember() BS.

      --
      I do not believe in karma. "Funny"=-6. Do good and forbid evil. Yours, Oft-Offtopic Flamebaiting Troll.
    45. Re:Common knowledge by Anonymous Coward · · Score: 0

      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.

      It's absolutely reasonable that a non-tuned (in code terms) C++ implementation outperforms a non-tuned ASM version. If you do vectorization and things yourself in ASM, you may be able to reach higher performance, but it's costly. Likewise, since C++ has more requirements than C, you can expect a C++ version to be faster than a C version because the compiler can apply more optimizations, and/or library data structures are often highly optimized, compared to special hand-written C code.

    46. 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
    47. Re:Common knowledge by drolli · · Score: 1

      Yes, dont you get that feeling more often?

    48. Re:Common knowledge by TheRaven64 · · Score: 1

      The 6g compiler is pretty primitive. It's really nice as a reference implementation, but as an optimising compiler it leaves a lot to be desired. Reading the assembly that it produces, I cringe slightly. It's about on a par with PCC in terms of generated code quality. If I have a few weeks spare at some point, I'm quite tempted to write a better one. Go would benefit from much of the same back-end stuff that I've done for Objective-C over the last couple of years and from developments in C compilers.

      --
      I am TheRaven on Soylent News
    49. Re:Common knowledge by Anonymous Coward · · Score: 0

      Code using arrays of characters should definitely be faster in Java, since you can assume it to not alias with other things, whereas in C and C++, pointers to char can alias with anything, preventing important optimizations.

    50. 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.

    51. Re:Common knowledge by obarthelemy · · Score: 1

      There's a kind of bias. The only thing the review takes into account is the performance of the code produced. It does not take into account the amount of time and resources needed to write that code, nor the amount of training and experience needed to reach that level of proficiency, nor the percentage of drop outs that never could reach that level. Also, it assumes maintainability is equivalent, which may be the case or not.

      The review is valid, as is saying that a formula one is faster than a family car. It may not be the whole story, nor very relevant. Also, they left out plain C and Assembly, which could probably do better than C++, but of course exacerbate the same issues.

      --
      The Cloud - because you don't care if your apps and data are up in the air.
    52. 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.
    53. Re:Common knowledge by Unoriginal_Nickname · · Score: 1

      I've already explained twice.

      w.r.t. finding free memory faster: A modern garbage collector pre-allocates memory in several large pages and condenses the free space to one end of these pages. Locating free space is worst-case Theta(n) in the number of pages - which is a small number, usually in the tens, and is stable and predictable. Malloc is worst-case Theta(n) in the number of free blocks, which is determined by a combination of malloc implementation details and usage (this is potentially all memory which is ever freed by the program.) Heap allocation in managed languages is indeed much faster than allocation in C or C++.

    54. Re:Common knowledge by Anonymous Coward · · Score: 0

      > in general a fairly floored benchmark

      ITYM "flawed"

    55. Re:Common knowledge by Anonymous Coward · · Score: 0

      That's when you would use weak_ptr.

    56. Re:Common knowledge by Unoriginal_Nickname · · Score: 1

      It's called a heap because it's a messy pile of junk. The heap data structure has nothing to do with it.

    57. Re:Common knowledge by w_dragon · · Score: 1

      C++ users seldom use malloc, in my experience, it's always new. And even then, reference counted pointers are far more common than raw pointers these days. A reference counted pointer gives you almost as good a guarantee as a GC, other than cycles causing issues, and you get deterministic deletion making RAII possible as a benefit!

    58. Re:Common knowledge by Joce640k · · Score: 1

      Oh yes. Why shouldn't a GC language where the GC has to search through lists regularly....

      Especially when you start swapping to disk. Oh yeah, search the whole heap space every two seconds why don't you...?

      --
      No sig today...
    59. 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...
    60. Re:Common knowledge by Joce640k · · Score: 1

      Have you used Electric Fence or Valgrind?

      Or a smart pointer...

      --
      No sig today...
    61. Re:Common knowledge by Xest · · Score: 1

      The problem for C++ is that even the "bad code" qualifier is generous, even average, or moderately well written code performs better in Java as standard, and it's only when you venture into the realms of extremely well written code that C++ starts to pull ahead.

      But there's another caveat too, under real world pressures of deadlines and cost constraints even the best developers in the world would struggle to find time to make sure their C++ code fits in the extremely well written box.

      So ultimately, unless specific performance enhancements are budgeted for within a project, which only really occurs incredibly rarely in specific performance sensitive projects, then C++'s ability to outperform Java only ever really arises in purely academic circumstances. C++ has it's advantages and place for sure, but the performance argument has become so irrelevant to most real world software development it's just meaningless. Even with the growth of complexity of computer games, the amount of time to develop is a far bigger issue than squeezing every less processor cycle out of the game such that even there C++'s performance advantages are becoming ever less relevant- it's the fact it's got strong cross platform support (i.e. the only language supported by all of the PS3, Wii, DS, PSP, 360, PC) that really gives it the advantage there rather than it's performance potential nowadays.

    62. Re:Common knowledge by Anonymous Coward · · Score: 0

      If you don't know when to free memory, you don't know what your code is doing.

    63. Re:Common knowledge by Anonymous Coward · · Score: 0

      Think of GC as an optimization of batching your scattered free() calls in your application into a well-scalable (read parallelizable) batch task.
      Also think of the GC as faster memory manager than malloc().

    64. 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.

    65. Re:Common knowledge by TheRaven64 · · Score: 1

      Check your history. The first implementations used a heap. Newer ones use some other tree-like structure. No shipping malloc() implementation has ever used a linked list.

      --
      I am TheRaven on Soylent News
    66. Re:Common knowledge by Anonymous Coward · · Score: 0

      From TFA: "Jeremy Manson brought the performance of Java on par
      with the original C++ version." Read on for the gory details.

      We all know the built-in Collection framework sucks badly (ArrayList.remove() does arraycopy, boxing/unboxing of Integers, Sets are really Maps, no reuse of Iterator objects and so on). So using better List / Map implementations is crucial for an algorithm like that one. If you do it right (TM), Java does solve most OO problems faster as C++.

    67. Re:Common knowledge by petermgreen · · Score: 1

      Or a smart pointer...

      One of the things in a language like C++ is that sooner or later you end up having to work with APIs that take plain pointers. That means you have to make plain pointers from your smart pointers. In some ways this is even worse than using plain pointers throughout because the early-free isn't directly visible in your code.

      But the bigger issue with memory corruption bugs is that the place(s) where they show up can be totally unrelated to the place(s) that cause them.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    68. Re:Common knowledge by serviscope_minor · · Score: 1

      Allocation of memory is a few instructions with a GC; malloc() can't hope to be in that same league.

      I've heard this one a lot. It is a deceptive argument precisely because it contains a grain of truth. It is very true, GCs can be made faster than malloc. But malloc isn't the fastest or most common way of allocating or deallocating variables in C++.

      The fastest and most common method is automatic storage. All local variables are manaed by the stack. Allocation is free: the space is already there and the size requirements are known statically. On function entry, the compiler knows exactly how much space will be used and makes sure that the space is already there.

      In other words, most variables are allocated and deallocated for free on function entry/exit using a simple addition/subtraction of the stack pointer.

      --
      SJW n. One who posts facts.
    69. Re:Common knowledge by Unoriginal_Nickname · · Score: 1

      weak_ptr can't be used naively either. Keep in mind that a cycle of any size will prevent shared_ptr from functioning, and it may not be immediately obvious that this is a problem.

    70. Re:Common knowledge by drolli · · Score: 1

      If you have heap which swaps heavily to disk, then please reconsider your system design. If you program uses a big amount of memory (of is used on a heavily loaded system), then its maybe a good idea to help manually/provide an own malloc.

    71. Re:Common knowledge by TheRaven64 · · Score: 1

      Ah, you're right. Sorry.

      --
      I am TheRaven on Soylent News
    72. Re:Common knowledge by Anonymous Coward · · Score: 0

      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.

      The GCC GC (ggc) is definitely NOT "just the Boehm GC with a half dozen small patches applied". Perhaps you've confused boehm-gc/ (the boehm-gc with a half dozen small patches) with gcc/*g{ty,gc}* (GCC's GC). If you're a GC writer yourself, you'd find it an interesting read. It's definitely a novel idea.

    73. Re:Common knowledge by Unoriginal_Nickname · · Score: 1

      Donald Knuth disagrees with you. He knows his history better than either of us.

      Actually many shipping malloc implementations use linked lists, such as dlmalloc and ptmalloc2, upon which the glibc implementation is based.

    74. Re:Common knowledge by icebraining · · Score: 1

      I'm pretty sure that modern machines use the DMA to fill memory blocks; even the DS has functions for that.

    75. Re:Common knowledge by TheRaven64 · · Score: 1

      Linked lists are only used in the implementations you list for allocations of the same size, not for finding an allocation of the correct size. A malloc() implementation using a linked list would not even be possible with vaguely correct semantics, because it would have to either return the first allocation large enough (probably wasting a lot of space), split the first allocation it found that was big enough (causing massive heap fragmentation), or traverse the entire list to find one of the optimal size. Linked lists are used in slab allocators and memory pools, and are used within malloc() for sub-allocators approximating these, but they are not used for the heap as a whole.

      --
      I am TheRaven on Soylent News
    76. Re:Common knowledge by Nitage · · Score: 1

      A compacting GC is often a win over naive manual memory management - they improve cache coherency and speed up dynamic allocation. Of course, using smarter allocation techniques (small object pools etc) instead of general purpose allocators (new/malloc) can provide even grater benefits to GC - but that's what Google were talking about when they said "extensive tuning efforts". In other words, a C# or Java application using GC can outperform a naive C++ application because of, not in spite of, GC. The worst case is when somebody decides that every dynamic allocation belongs inside a shared_ptr *shudder*.

    77. 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.

    78. Re:Common knowledge by Anonymous Coward · · Score: 0

      And more so most small objects in c++ will exist on the stack, meaning exactly 0 instructions for allocation. Better to not produce garbage in the first place rather than to efficiently recycle.

    79. Re:Common knowledge by Unoriginal_Nickname · · Score: 1

      No, ptmalloc2 stores all free chunks in (doubly-) linked lists. It sorts them into bins by size to improve speed and reduce fragmentation.

      Your comment about 'vaguely correct semantics' is complete nonsense. Implementing malloc using linked lists is a good exercise for first year undergraduates; it's clear that such an idea works.

    80. Re:Common knowledge by kbw · · Score: 1

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

      Being wrong doesn't make them idiots.

    81. Re:Common knowledge by Short+Circuit · · Score: 1

      Among established languages, I assume it's common knowledge that C++ has been the highest-performance language, for definitions of performance non-inclusive of developer time spent optimizing*. Nevertheless, there are always new languages being developed by enthusiasts, academics--even some businesses, which approach the problem of high-performance code from different angles.

      * God, to say anything accurate and comparative on the subject, one has to add so many scope qualifiers that it becomes, well, almost meaningless...

    82. Re:Common knowledge by joss · · Score: 1

      > even average, or moderately well written code performs better in Java as standard

      Citation please. That's not my experience at all, but its a few years since I was a full time C++ head. Standard java performs terribly because the whole culture encourages wasteful development, its possible to make java almost as fast as C++ but only if you really know what you're doing and avoid the pitfalls of the java standard library. Games developers aren't developing in c++ for fun or even the cross platform issues, they're doing it because they want their games to compete with those put out by other companies.

      --
      http://rareformnewmedia.com/
    83. Re:Common knowledge by mgpl777 · · Score: 1

      Alex Trebek: This language has the best performance. It's almost "D".
      Watson: What is JAVA?

    84. Re:Common knowledge by wisnoskij · · Score: 1

      No it is common knowledge that this is wrong, obvious Assembly is faster then C++, if given extensive tuning by sophisticated programmers.

      And is the article not actually saying that no it is not faster in most cased, because most people will not or cannot spend hundreds of hour tuning their code (not even to mention that it require a C++ expert to even attempt this).

      --
      Troll is not a replacement for I disagree.
    85. Re:Common knowledge by Anonymous Coward · · Score: 0

      research = common knowledge + credentials

    86. Re:Common knowledge by wisnoskij · · Score: 1

      Oh give me a break, yes controlling every thing does allow you the possibility of optimizing to perfection but in 99.99-% of the cases it is better to leave the optimization to the experts who wrote the optimization part of the compiler. And Java does have a few aspects in it that make optimization easier. So sure it is not faster or as fast a C++ but it could be (at least minus the slight lag that not compiling directly to an EXE introduces)

      --
      Troll is not a replacement for I disagree.
    87. Re:Common knowledge by gbjbaanb · · Score: 1

      Its a bit more complex than that. My brief and slightly non-technical explanation goes:

      GC is faster for allocations - all it does is grab another block at the end of the heap and say "here you go". That's about as fast as memory allocation can get and is comparable to allocating off the stack (where you just increment the stack pointer register).

      The problem starts to show when you need to de-allocate memory. Obviously, the GC doesn't bother doing this very often and is why benchmarks can show stunning performance for a GC, but then benchmarks are often like that. When the GC needs to fre up a load of memory, it locks the heap, then searches through the allocated blocks looking for pointers to them, marks the ones that are not pointed to and then at the end, freers them up. It then copies the memory that is currently allocated down to close up holes that were freed in the heap, so it can resume its allocation-by-giving awya blocks from the end.

      This is a rather slow process (ignore the idiots who say that GC collections take next to no time, they're hyping up their preferred technology). Its so slow that the generational GC was invented. This effectively is 3 GCs in 1, partitioning the heap so that the run-through-the-heap collection phase only has to be applied to a smaller set of blocks.

      Now with traditional heaps, the allocation and de-acllocation occurs regularly so the performance hit (which is roughly the same as the overall GC hit) is spread out continuously. This means you see slower performance .. until you get to the GC collect phase when things even themselves out. Except there is a performance hit - as you allocate and free blocks you often don't allocate the same sized blocks as you freed, so the memory system has to 'walk the heap' looking for a free block that is big enough for you. This means that the longer you run your program, the longer it takes as you will have a more fragmented heap. There are techniques to solve this - using multiple fixed-blocksize heaps means freeing a block really will be big enough for another allocation so you only have to remember the position of the first free block, but this costs more memory (not that this is an issue if you're comparing to a GC that is inefficient with memory usage too!)

      Now, the place where the GC does shine is down to the language that uses it. In a GC languages like java or C#, when you allocate an object it comes off the heap. In a non-GC language like C++, you can still allocate off the heap, but you generally allocate on the stack - this is faster than the GC, but when you leave your functions and the stack loses all local variables, if you want to keep that object, you have to copy it. These repeated copies can slow things down a lot (eg in debug versions of the STL), which is why most compilers optimise the copy away (ie instead of allocate an object on the stack, then copy it to another location further down the stack, it allocates it directly where it would have been copied to).
      In a GC language, this copy step is not applicable as you only have a pointer to move around the place. Sometimes this means large objects are faster to deal with.

      In the end though, it depends entirely on the programmer's use of memory and language features. A junior dev using C# can copy a huge object all over the place and not notice any performance issues. The same guy using C++ would see huge hit to perf. If he had more knowledge of when to use the stack and the heap, then he could allocate said object more appropriately and get the same perfomance as C#. Similarly, the same coder in C# could too easily create lots and lots of 'temporary' objects on the heap that a C++ dev wouldn't do, thus making his C# app much slower than the C++ guy.

      So.. GC.. is it bad or not? Not in itself. Is it a magic bullet to solve all memory issues.. not in itself.

      Generally I prefer non-GC languages as there is 1 truly important aspect that is often glossed over:

      GC only handles memory well. that's its whole

    88. Re:Common knowledge by rjstanford · · Score: 1

      This is a key point.

      Also, one of (if not the) main goal of Java today is that it is very, very hard to write unmanageable code in it. Its still possible, don't get me wrong, but I'd much rather be dropped into the middle of a million lines of Enterprise Java than a million lines of Enterprise C++ to try to figure out a problem.

      Not that either of those scenarios would be fun, mind you. But they do happen. As long as Java is easier to maintain and fast enough, it'll do just fine.

      --
      You're special forces then? That's great! I just love your olympics!
    89. Re:Common knowledge by Suiggy · · Score: 1

      GC does not a fast compiler make. Clang, a C/C++ compiler, for example does not use garbage collection, it uses a variety of hand-tuned, manual memory allocators and it is as much as 4x faster on average than is GCC.

    90. Re:Common knowledge by Anonymous Coward · · Score: 0

      You guys are all bitches.

      exit() is my garbage collector.

    91. Re:Common knowledge by TheRaven64 · · Score: 1

      You're even contradicting yourself. ptmalloc2 sorts free chunks into bins and then uses a linked list as a secondary data structure for similar sized chunks. Which is exactly what I said in my original post...

      --
      I am TheRaven on Soylent News
    92. Re:Common knowledge by Unoriginal_Nickname · · Score: 1

      The bins ARE linked lists.

      Stop embarrassing yourself: read Knuth, read the source code, stop making up shit.

    93. Re:Common knowledge by LWATCDR · · Score: 1

      Funny but I would say the same thing about the java haters. I love you got that from study.
      This was one test but the results are very interesting. The Java version was the easiest to implement. That has real value because many programs do not demand a lot of performance. Java would be a terrible choice for an OS, Browser, or anything that is really high performance. If you are going to write a Point of Sale System, a Home Accounting system, or any number of simple programs like that Java seems like a really good option. Add in it being multi platform and it is actually a good solutions for many types of programs. C++ is for anything that is going to be really demanding and when it is worth the time to really fine tune the code. It is almost always going to be the wrong language for a one off program.
      For one offs Python and Perl are good and frankly so is Java.
      Scala also seems really interesting it is producing faster code while running on the JVM which is really interesting.
      One and C++ can be very close to multiplatform if you use QT but it takes a lot of work.
      Different tools for different jobs. Java for some jobs will allow you to get out a reliable program into the hands of users much quicker than using C++ and that has it's own value. Think of Java as a container ship and C++ as a 747-F.
      Maybe you should have read the conclusions.
      C++
      "We nd that in regards to performance, C++ wins out by a large margin. However, 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"
      So if you are working on performance critical code C++ is the way to go.
      For Java
      "The Java version was probably the simplest to implement, but the hardest to analyze for performance. Specically the effects around garbage collection were complicated and very hard to tune"
      For speed of development and reliability are more important the speed of execution then Java seems like a good solution. For many programs all you need is for the program is fast enough all you need to do is have it be fast enough for your user to not have to wait. This is a large segment of software. Think of things like ATMs, Point of Sale System, or any of those Form plus data base programs that people use everyday.
      Scala really interests me a lot
      "Scala concise notation and powerful language features allowed for the best optimization of code complexity." I may really have to give this a long hard look.
      And then you have GO.
      "Go offers interesting language features, which also allow for a concise and standardized notation. The compilers for this language are still immature, which reects in both performance and binary sizes." To me this is a case of it not being ready for prime time yet.
      Java can be as fast as C++ when you define fast as user perception. The few milliseconds improvement you may get with an Home Accounting system will not matter one bit to the users.
      I wouldn't write a browser or a Flight Simulator in Java but there a lot of good programs written in Java and it is a good tool for some uses.
      Maybe you should take a look at the conclusions of the study before you start bashing.

      --
      See my blog http://ilovecookes.blogspot.com/ for light hearted technical information.
    94. Re:Common knowledge by TheRaven64 · · Score: 1

      The contents of the bins are linked lists, but allocation does NOT search the list, it finds the bin. All malloc implementations that you will use are log(n) at worst, and most are constant time for common allocation sizes. You never have to, as you claimed, search a linked list for a bit of free memory, because no one (except, apparently, you) is stupid enough to write a O(n) malloc(), let alone a theta(n) malloc().

      Knuth's algorithm used a tree of power-of-two sized objects, creating smaller ones by subdividing the larger ones if required, and returning older ones to the head of a list dangled off the end of each tree node. To free, you needed to do a log(n) tree search to find the correct place to insert. To allocate, you needed to do a log(n) tree search to find the correct size and then a O(1) operation to grab the head element from the list (or request more memory from the OS[1]).

      You seem to have learned just enough complexity theory to be dangerous. Linked lists are used in malloc() because adding an element at the head and removing the head element are constant time operations. This does not mean that you have to do a linear search to find a free chunk - that would be insane.

      Generational garbage collectors like the Java one that you seem to have partially understood use bump-the-pointer allocation (from per-thread pools on most recent implementations), which is very fast, but for longer-lived objects comes with lots of extra overhead because once the small pool is allocated the GC scans, finds the live objects, and copies them to a longer-lived generation (typically also using bump-the-pointer allocation, although using tree search in some cases for heap compaction without as much copying overhead - see the latest Sun design). For objects that are allocated and freed between GC invocations, this is a clear win, because the allocation cost is a couple of instructions. For others, you have two cheap allocations, but you also have the overhead of copying, which causes cache churn and can be significantly slower in the worst case.

      [1] The OS, by the way, typically DOES store free pages in a linked list, which may be the source of your confusion. It can do this because pages are all the same size and, NUMA aside, it doesn't matter where in physical memory a new page comes from.

      --
      I am TheRaven on Soylent News
    95. Re:Common knowledge by Anonymous Coward · · Score: 0

      No- being wrong about that does.

    96. Re:Common knowledge by Cyberax · · Score: 1

      Though there IS a sub-project in GCC to try and use Boehm instead of their own GC.

    97. Re:Common knowledge by Unoriginal_Nickname · · Score: 1

      Nobody is stupid enough to write an O(n) malloc?

      You realize that any algorithm in O(1) is also in O(n), right?

      Don't lecture people about complexity theory until you understand it. Or anything else, for that matter.

    98. Re:Common knowledge by Unoriginal_Nickname · · Score: 1

      [1] The ptmalloc2, by the way, *urkel snort*, DOES use linked lists for everything. Like I said. The tree structure thing you mentioned? Complete bullshit, just like your remark about the origin of the term 'heap.'

    99. Re:Common knowledge by Anonymous Coward · · Score: 0

      Of course C++ is faster. Just write all of your code in hand-tuned assembler disguised as a C++ application.

    100. Re:Common knowledge by VGPowerlord · · Score: 1

      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.

      And this is precisely why Microsoft's (former) Java clone, C#, has a using block which automatically frees the object you create at the start of the block.

      --
      GLaDOS for President 2016! "Well here we are again. It's always such a pleasure." -- GLaDOS, 2011
    101. Re:Common knowledge by siride · · Score: 1

      I'm pretty sure that free() doesn't send pages back to the OS until the heap can definitely be shrunk enough to make it worthwhile. Fragmentation would, for example, prevent shrinking the heap.

    102. Re:Common knowledge by SanityInAnarchy · · Score: 1

      It does, however, mean that you're effectively running some sort of garbage collection all the time. Java can just pass a pointer around; you have to pass a pointer and increment/decrement something. Java might interrupt your program to do some GC; you might call free/delete whenever any given reference falls out of scope.

      It might matter less now, but this did occasionally have advantages -- aside from the efficiency gains of having at least some amount of buffer so as to not always be allocating/freeing directly to/from the OS (and I bet someone can optimize C++'s new/delete to do the same thing), there's also the fact that having all your GC code in one place, such that your normal code isn't even calling it, makes your normal code faster, and more importantly, smaller, so it all fits into cache. Then, when a GC cycle hits, the GC itself is all in one place, so it all fits into cache.

      On the other hand, the less often a given GC cycle runs, the more likely it is to involve a fair number of cache misses (even just to find out what memory is in use), whereas sufficiently small/light branches of C++ code might allocate, use, and free all of their memory over and over again without any cache misses.

      I should really shut up until more profiling is done, which means I should probably RTFA.

      --
      Don't thank God, thank a doctor!
    103. Re:Common knowledge by SanityInAnarchy · · Score: 1

      Yeah, you would hope there'd be a hardware provision to clear memory blocks. You'd also hope that there's some amount of buffer between malloc/free/new/delete and actually returning that memory to the OS or allocating more.

      --
      Don't thank God, thank a doctor!
    104. Re:Common knowledge by Anonymous Coward · · Score: 0

      They did try Java++

      And it (Scala) had the better speed than everything but C++ and had the shortest program by a factor of 2.5.

      For most things that is a good trade off.

       

    105. Re:Common knowledge by EvanED · · Score: 1

      C++ users seldom use malloc, in my experience, it's always new. And even then, reference counted pointers are far more common than raw pointers these days. A reference counted pointer gives you almost as good a guarantee as a GC, other than cycles causing issues, and you get deterministic deletion making RAII possible as a benefit!

      None of which has any applicability to what I said.

      'new' has to do the same thing to allocate memory behind the scenes that 'malloc' does* (and is thus slower than a GC 'new'), and since even smart pointers "can't" move objects around, they don't do the same automatic locality-improving, heap-defragmenting behaviors that I said are subtle benefits of GCs.

      If you want to get into how useful GCs are specifically, then talking about smart pointers is relevant, but aside from my final insinuation, I wasn't talking about that at all. (Even that last thing wasn't so much talking about GCs in terms of making it easier to manage memory so much as the practical relation between languages that are memory safe and the languages that have GCs.)

      * It's very likely that your platform's 'new' is implemented in terms of malloc. (Or that 'malloc' is a thin wrapper around something else, and 'new' is implemented in terms of that.)

      Here is part of 'new_op.cc' from GCC 4.6.0's distribution:

      _GLIBCXX_WEAK_DEFINITION void *
      operator new (std::size_t sz) throw (std::bad_alloc)
      {
        void *p;
       
      /* malloc (0) is unpredictable; avoid it. */
        if (sz == 0)
          sz = 1;
        p = (void *) malloc (sz);
      ...

    106. Re:Common knowledge by EvanED · · Score: 1

      That's sort of why I put it in quotes. But you're right; "mimic" would be closer, or even just "do something similar as". :-)

    107. Re:Common knowledge by ginbot462 · · Score: 1

      Are you me in another life? I'll just link to this when I make the same exact statements (down to years professionally developing && the languages - which admittedly is linked to the previous).

      --
      Atlas Shrugged : Thematic Story :: Battlefield Earth : Organized Religion
    108. Re:Common knowledge by sribe · · Score: 1

      Not really. Recent malloc() implementations use per-thread pools, so free() just returns the memory to the pool (so do most GCs).

      Yes, but OP's post was about the situation where you free a block in different thread than you malloc'd it--note that the free call must account for this possibility on every call, unlike malloc.

    109. Re:Common knowledge by Estanislao+Mart�nez · · Score: 1

      Oh yes. 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?

      Actually, your question just goes to show you don't understand the GC-vs.-malloc performance issue.

      In a pure worst case time complexity analysis, assuming there are at least some objects to be collected or freed, malloc/free is costlier than stop-and-copy GC:

      • Free has to pay a cost to deallocate each object it frees. In stop-and-copy GC, there is no corresponding cost; collected objects are just not visited by the collector.
      • Malloc has to scan and modify a non-trivial a data structure to find a free block large enough to satisfy each call. Stop-and-copy GC just needs to increment a pointer.
      • Malloc/free can suffer from heap fragmentation, which makes its performance degradate over run time. Stop-and-copy compacts the heap.

      Of course, in practice malloc/free is faster. But this is because for completely different reasons than what you say:

      • Stop-and-copy GC has a larger memory footprint.
      • Stop-and-copy GC will periodically go and touch most of the pages in your application's virtual memory, which is penalized by processor cache and OS virtual memory managers.

      In effect, part of the problem is that CPUs and VMMs are designed for the benefit of programs that use C-style memory management, and not for those who use GC.

    110. Re:Common knowledge by EvanED · · Score: 1

      That's like how you described my statement: deceptive because it's got a kernel of truth. ;-)

      Most programs that people directly interact with make extensive uses of the heap. Out of 79 processes running on my Win7 box now (I think that even counts the idle process), 22 of them have over 10MB of private memory in their working set. 10 have over 25 MB, and Opera has over 1 GB.

      The default max stack size with MSVC is 1 MB. Even if half of those process' memory are globals/statics, that means that they are holding several times as much memory in the heap as on the stack.

      Basically what I'm saying is that even though most variables are on the stack, almost all programs that do interesting things (apart from some scientific code that uses statically-sized arrays) is going to do substantial heap work.

    111. Re:Common knowledge by Anonymous Coward · · Score: 0

      Neither the C nor the C++ standards specify that the heap is a "linked list." Nor do they specify the algorithms to access said heap. That is up to the implementations. Hell, the languages don't even dictate that a heap is used.

    112. Re:Common knowledge by SETIGuy · · Score: 1

      you free a block in different thread than you malloc'd it

      I just threw up in my mouth a little.

    113. Re:Common knowledge by ImprovOmega · · Score: 1

      C++ will always be faster if for no other reason than having support for inline assembly.

      While yes, technically that means it's assembly, not C++, the ability to drop into a low-level language for those 10 lines of high critical code means that you can easily hand optimize better than any interpreted or JIT language could ever dream. Audio decoding + SSE/MMX = Win.

      You sacrifice any chance of portability, but you can make it scream on its native hardware.

    114. Re:Common knowledge by sribe · · Score: 1

      I just threw up in my mouth a little.

      Uhm, inter-thread communication? Work queue? Provider/Consumer? It should be rare indeed for a block to be freed in a different thread than it was malloc'd in. But there are legitimate reasons why this happens for a small number of them, and so the allocator has to account for this. Simply assuming that free happens in the same thread as malloc, and adding the block back with no checking/locking would be a disastrous bug for an allocator. (Now, one could imagine an allocator that allows control over this, but that would introduce some rather tricky issues that would become a very likely source of hard-to-find bugs.)

    115. Re:Common knowledge by ImprovOmega · · Score: 1

      Well, once the program is finished, ASM is faster than C++. The problem is, your deliverable time on a 100k lines of code C++ project redone in hand optimized assembly is approximately equal to the number of years until the heat death of the universe.

    116. Re:Common knowledge by TheRaven64 · · Score: 1

      No, that's not how most per-thread allocators work. They periodically return memory to a shared pool (or to the OS directly in a few cases), but this means that they only need to synchronize after a certain number of calls, not every call. Memory can be allocated by one thread and freed by another, but if both threads are freeing approximately as much memory as they are allocating then this balances out and neither has to touch the global allocator lock very often.

      Unbalanced malloc() and free() calls across threads are one of the most common causes of implicit synchronisation in multithreaded code, and can be a reason for hitting Amhahl's law problems a lot sooner than intuitively expected.

      --
      I am TheRaven on Soylent News
    117. Re:Common knowledge by non0score · · Score: 1

      The argument between GC vs. manual memory management a la malloc/free is partly why there exists a debate if Java is as fast as C/C++.

      First of all, there's no clear line between "GC" vs. "manual memory management". At some point, writing your own GC for your data structure is both "GC" and "manual memory management" at the same time. Unless you're talking about the default GC, otherwise GC is just a form of memory management.

      Secondly, anyone who knows how to do heavy multithreaded programming on C/C++ knows to not rely on the global malloc and free. Either you use the platform-specific memory allocate and commit routines, or you use malloc and free very sparingly. After you get the chunk of memory from the system, you manage it yourself, using the appropriate memory allocator suitable for your data requirements. There is absolutely no one-size-fits all solution that runs fast.

      As for handcrafted asm seldomly outperforming compiler code, that's probably because most asm writers are just doing it for the knowledge and experience, and not for real optimization purposes. Real asm code in tight loops done by pros usually outperform their compiler counterparts on the orders of 10~100x. At work, one of our pros even got to 1000x once...and that pro is no slouch when it comes to plain C. Of course, modern Intel CPU architectures throws a huge wrench in that analysis...but you pay for that in terms of power and die size...something not visible to the average programmer.

      The moral of the story is, if you take the worst practices of one language and pit it against the best practices of another language, then sure, you may get "surprising" results.

    118. Re:Common knowledge by Anonymous Coward · · Score: 0

      Bingo. Wish I had mod points.

    119. Re:Common knowledge by sribe · · Score: 1

      No, that's not how most per-thread allocators work. They periodically return memory to a shared pool (or to the OS directly in a few cases), but this means that they only need to synchronize after a certain number of calls, not every call.

      That's a good clarification. This method accomplishes exactly the goal of "accounting for the the possibility" of free being called in a different thread than the one in which the malloc is called, while reducing the amount of locking. (I assume that in what you're describing, each free puts the block onto a per-thread non-locked pool pending the periodic move to a locked shared pool...)

      Unbalanced malloc() and free() calls across threads are one of the most common causes of implicit synchronisation in multithreaded code, and can be a reason for hitting Amhahl's law problems a lot sooner than intuitively expected.

      Makes sense. It's nice that sufficiently-sophisticated allocators can, as you describe, limit this problem to unbalanced calls rather than the more general case of malloc/free across threads. But there's only so much an allocator can do for you, ultimately moving data between threads necessarily becomes a limit to parallelization.

    120. Re:Common knowledge by TheRaven64 · · Score: 1

      I didn't say that hand-coded asm won't outperform the compiler, I said that the examples where it does are small programs or individual functions. If you rewrite a 100 line function in hand-crafted assembly, you can probably do a better job than the compiler. This isn't surprising, because the compiler is applying the same tricks that you will, but it's constrained to only being able to do so when it can prove that they are safe from what you've written, while you have extra knowledge about the program that is not explicit in the small part of code that the compiler can see. If, on the other hand, you try rewriting a 300,000 line project in assembly then I doubt that you'll finish, but if you do then I doubt that you'd be faster than the compiler, because you won't have the patience to apply those same optimisations everywhere.

      Memory allocation is the same. I can write an allocator that can outperform a general GC in pretty much any situation. But most of the time, I can't be bothered, and I'll just use a fairly simple scheme if I'm doing manual memory management, and even something like the Boehm GC is likely to do at least as good a job. These days, I rarely bother optimising my code - if I see a pattern that can yield an improvement, then I write a compiler pass and let it apply it everywhere. Life's too short to solve the same problem more than once.

      --
      I am TheRaven on Soylent News
    121. Re:Common knowledge by MobyDisk · · Score: 1

      How could C be faster than C++ when C++ is a superset of C, with some additional features? Most C compilers are C++ compilers too, they just disable certain language constructs when in C mode.

    122. Re:Common knowledge by serviscope_minor · · Score: 1

      Sure, most things make extensive use of the heap. Specifically I'm referring to simply the frequency of allocations and deletions. I'm not sure the size of allocations matters all that much. I'd expect most programs to allocate/deallocate more local variables than they instantiate/delete heap space. I don't know if that is a valid assumption in general, but looking at my own code, I often instantiate lots of loop counters, indices, etc compared to the number of big objects.

      --
      SJW n. One who posts facts.
    123. Re:Common knowledge by Jorl17 · · Score: 1

      You can code special classes that avoid almost all increments and decrements, so you don't have to do them yourself. It's similar to writing a class that handles itself around threads just fine -- it deals with it internally.

      Other than that I agree with you.

      --
      Have you heard about SoylentNews?
    124. Re:Common knowledge by frank_adrian314159 · · Score: 1

      If you try to open 100K files in C++, it likely won't work either. And I've seen plenty of newbie C++ programmers try to to similarly boneheaded stuff. The issue isn't programming-language-related. It's that what you're taught in school doesn't scale, regardless of the language. It's about experience, not language.

      --
      That is all.
    125. Re:Common knowledge by Anonymous Coward · · Score: 0

      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.

      That depends on theory versus reality. C++ cannot be faster than ASM because it's mathematically demonstrable that every C++ program can be transformed into an ASM/machine-language program (that is, after all the definition of a compiler), but not vice versa.

      In reality, this breaks down on large applications for one simple reason. The larger the program, the more places that are likely to change when changes are made in the course of normal maintenance. As the size increases, the amount of incidental maintenance becomes first uneconomical, then for all practical purposes humanly impossible.

      Early compilers were fairly stupid and a good assembler programmer could easily outdo them. As time progressed (and software ballooned), this was no longer true. As long ago as 1986, IBM was producing commercial compilers that could completely reassign the entire set of register usages every time you recompiled even the smallest code change. Personally, I have better things to do with my life, so I started losing interest in assembler for non-trivial projects at that point. Besides, my boss wouldn't let me.

      Moving even further along, pipelined processors and other non-linear architectures came along and you could no longer count on easily-calculated instruction execution times, since the context mattered as much as the instructions. Automated translators can handle the extra math. Again, I have better things to do.

      Cut to the modern era. Only fools believe that "Java is an interpreted language, therefore slower than C++". The JIT compilers have been around for quite a while now. Obviously small Java apps are going to be horribly disadvantaged, since there's both the overhead of setting up the JVM and the overhead of JIT, but Java isn't primarily intended for small apps these days (assuming there's anything left that can be called "small" anymore). Where Java can wipe the floor with C++ and wring it out to dry is the really heavy stuff. That's because no matter how much hand-optimization you do in C/C++, the code, once compiled is optimized for the particular case you expected to encounter. It's static.

      That's where Java is different. Java doesn't even employ JIT until it has determined that the code is used often enough to benefit from being compiled instead of interpreted. But once compiled, Java monitors execution in real time, and if it sees code operating sub-optimally, it will compile to an entirely new set of machine instructions better tuned to real-world experience. And do so repeatedly, as time progresses.

    126. Re:Common knowledge by lxrslh · · Score: 1

      Not being an "expert" in any of these languages, I actually RTFA and discovered the following on Page 9: "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." Sounds to me like Java can be as fast as C++. YMMV....

    127. Re:Common knowledge by BravoZuluM · · Score: 1

      I completely concur. I don't experience memory crashes or memory leaks in my programs. There are well documented best practices that make this a thing of the past. Adding QT to the mix has made the C++ experience extremely pleasant.

    128. Re:Common knowledge by BravoZuluM · · Score: 1

      If you have circular references, there is a problem with your design. Usually people have circular dependencies when object a needs to talk to object b, and object b needs to talk to object a. Take a look at signals and slots. That will help decouple your classes.

    129. Re:Common knowledge by SETIGuy · · Score: 1

      I realize the allocator has to account for it. I've always felt that deallocating in a different thead should be avoided except in the very rare cases when it can't, even if it means some extra work.

      Maybe I'm wrong. Maybe C++ and C libraries have gotten to the point where cross thread allocation/deallocation are reliably thread safe and foolproof. Maybe I can trust other programmers to do the right thing. Maybe debuggers are better at debugging problems arising from this. Maybe I'm still living in 1995.

    130. Re:Common knowledge by grmoc · · Score: 1

      increment/decrement is *extremely* cheap.

    131. Re:Common knowledge by sribe · · Score: 1

      I realize the allocator has to account for it. I've always felt that deallocating in a different thead should be avoided except in the very rare cases when it can't, even if it means some extra work.

      Certainly.

      Maybe C++ and C libraries have gotten to the point where cross thread allocation/deallocation are reliably thread safe and foolproof. Maybe I can trust other programmers to do the right thing. Maybe debuggers are better at debugging problems arising from this.

      I think debuggers are better. But beyond that, it's still tricky.

    132. Re:Common knowledge by Darinbob · · Score: 1

      No, assembler should have beaten out C++ by a good margin.

    133. Re:Common knowledge by Darinbob · · Score: 1

      For many applications where memory is frequently allocated and freed, garbage collection has been shown to be as fast as traditional memory management. And this was shown before Java even existed. Do not take the naive approach of assuming a naive garbage collector was used. How can it be 2011 and people are still massively ignorant of garbage collection technologies from 1980's?

      For instance take into account that a free() operation has to be performed compared to merely doing nothing. Then all the code that has to check "if (ptr != 0)" everywhere in the code. Then worry about memory fragmentation and locality of reference. But I shouldn't mention such advanced terms to someone who still thinks garbage collectors search through lists regularly.

    134. Re:Common knowledge by Darinbob · · Score: 1

      Java has done GC wrong in many ways. Objects that should be freed immediately should have an explicit free function (ie, files, sockets, etc). But do not extrapolate from the faults in Java to assume that the GC concept is faulty. Faulting GC because of Java is as silly as faulting GC because it's slow in Emacs.

      Java did not invent anything and should never be used as an exemplar.

    135. Re:Common knowledge by MikeBabcock · · Score: 1

      The argument presented was that using a GC allows for better algorithms. Better algorithms aren't necessarily faster, they may simply be more correct or generate smaller, better or faster code.

      How is the speed of programs output by GCC vs. CLang in a benchmark?

      --
      - Michael T. Babcock (Yes, I blog)
    136. Re:Common knowledge by Prune · · Score: 1

      C++ is often faster than C for several reasons: the compiler can do much more inlining, you can do some large scale optimizations using template metaprogramming (even in the simplest case of expression templates, you can even beat out Fortran for scientific computing), etc.

      --
      "Politicians and diapers must be changed often, and for the same reason."
    137. Re:Common knowledge by Darinbob · · Score: 1

      This is true. Garbage collection or manual memory management should be equivalent in the general case. In special purpose cases you can usually just come up with a special purpose method of dealing with memory (ie a data structure specifically for editing massive amounts of text character by character, or memory pools, etc). Garbage collection is meant as a fast general purpose memory management technique, just as malloc/free is meant as a fast general purpose memory management technique. When you have a very specific application and detailed knowledge of exactly how much memory you will have at run time, then neither approach is best. Even memory pools have serious disadvantages much of the time.

      I think during the early 80s we had a ton of people try out Franz Lisp on BSD and come to the firm conclusion that GC is inherently slow, and these people have never wised up and have spread this misinformation ever after. They probably still think GC is done with reference counting or full mark-and-sweep.

    138. Re:Common knowledge by EsbenMoseHansen · · Score: 1

      Valgrind takes a lot longer to run any decent-sized program. But otherwise, yes... it's a pretty amazing tool.

      --
      Religion is regarded by the common people as true, by the wise as false, and by rulers as useful.
    139. Re:Common knowledge by MikeBabcock · · Score: 1

      Last I checked you can write native assembly objects to be linked into most other languages too, including Python and Java.

      There's no reason to be hung up on it in C++.

      --
      - Michael T. Babcock (Yes, I blog)
    140. Re:Common knowledge by Darinbob · · Score: 1

      But not necessarily as cheap as just assigning the pointer. Reference counting is a very naive way to do GC and has some serious drawbacks including speed. No serious GC system uses it, you only ever see it in roll-your-own GC wrappers or simple scripting languages in their early releases or as examples of how not to do GC in textbook. Why do people encourage the reuse of code and discourage reinventing the wheel, only to turn around and reinvent reference counting again and again?

    141. Re:Common knowledge by malsbert · · Score: 1

      O(1) != O(n);
      O(1) == "const time";
      O(n) == "linear time";

      --
      "Men will never be free until the last king is strangled with the entrails of the last priest." - Denis Diderot.
    142. Re:Common knowledge by EsbenMoseHansen · · Score: 1

      You know, there are gotchas in GC, too.

      Cyclic memory references are quite rare anyways... I can't remember the last time I had one of those (not counting linked lists, usually handled by a library). Admittedly, I very use shared_ptr's anyway.. I prefer aggregation to association whenever I can. Which means scoped_ptr/auto_ptr/... or better yet plain stack allocations most of the time.

      My mean beaf with GC is that it makes handling all other resources a pain. My second-largest beaf is that memory problems often are an indicator of poor design (you are not clear which class has what responsibility), which you loose with GC.

      --
      Religion is regarded by the common people as true, by the wise as false, and by rulers as useful.
    143. Re:Common knowledge by Darinbob · · Score: 1

      Or just mark the pages as zeroed in the cache. Then when you write the data before reading nothing needs to be done, and if you read data before writing it then the cache line is zeroed for you.

    144. Re:Common knowledge by Darinbob · · Score: 1

      I think many of the C++ advocates also advocate having lots more memory than you need, and will claim that memory costs are dropping all the time so you shouldn't worry about wasted space. This is a far different world than when GC was first thought up, and different than even the later malloc/free world. People used to worry about memory being scarce, and page misses being slow, and caches being amazingly expensive. This is still very true in a lot of systems but we just have so many people now who assume all computing occurs only on PCs.

      I hit this sort of snag with memory pools on embedded systems. You want the pools big enough to cover the worst case, but in the average case the majority of your memory is unused. And if you've got the worst case memory usage in pool #1 chances are that pool #2 is unused. But if you go with malloc then you've got the headache of fragmentation to deal with, plus the possibility that an allocation could fail. So things tend to be a mix of pools plus malloc. (and it's usually a smaller malloc to save space, which often means performance hits when scanning free lists)

    145. Re:Common knowledge by Darinbob · · Score: 1

      Any real GC system won't do this. You do incremental generational scavenging instead which never scans the entire heap and can actually improve paging performance.

    146. Re:Common knowledge by marcosdumay · · Score: 1

      "On a whole, GCs improve the memory locality of your program as it runs"

      Only if you write those malloc statements wrong. The GC does nothing that you can't do with manual allocation, and the reverse is false.

    147. Re:Common knowledge by marcosdumay · · Score: 1

      "It's reasonable to doubt that C++ is faster than ASM"

      Yep.

      "it's reasonable to doubt that C++ is faster than C"

      Why would it be? You can write C++ code that compiles into the same thing as normal C code, as you can write C code that compiles into the same thing as any variety of C++ one can think of.

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

      Again, why so? you can do the same hand tunning at the C++ libraries. In fact, you can do even more, but for numerical libraries it shouldn't be any difference.

    148. Re:Common knowledge by ultranova · · Score: 1

      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.

      And I've been using programs a lot longer than 10 years now, and seen enough buffer overruns, memory leaks and General Protection Faults/Segmentation Violations that yes, it's generally true. Most programmers are about average, and it only takes a single programming mistake to crash a program, or let malware in.

      Automatic memory management isn't training wheels, it's a damn seatbelt.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    149. Re:Common knowledge by EvanED · · Score: 1

      To get the same effect you'd have to replace malloc entirely. Then you'd have to be able to relocate existing objects and patch up pointers.

      You can do it in C, but you'd not be using malloc except, perhaps, for the initial allocation.

    150. Re:Common knowledge by shutdown+-p+now · · Score: 1

      The equivalent language feature for Java is part of Project Coin, and is coming in Java 7.

    151. Re:Common knowledge by ultranova · · Score: 1

      So... comparing two heap allocation routines is deceptive, but comparing stack allocation to heap allocation isn't?

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    152. Re:Common knowledge by shutdown+-p+now · · Score: 1

      The default max stack size with MSVC is 1 MB. Even if half of those process' memory are globals/statics, that means that they are holding several times as much memory in the heap as on the stack.

      But that's not a very good measure, because alloc count does not map directly to allocated block size. I can allocate a several megabyte char array to store an image, or a piece of cached HTML, for example (in case of Opera) - but that will still be a single malloc/new call.

      In truth, amount of heap allocations in C++ largely depends on coding style. Some frameworks (e.g. Qt) often force one to heap-allocate where it's not strictly necessary. Idiomatic C++ ones (such as STL and Boost) generally try to avoid gratuitous allocations.

    153. Re:Common knowledge by ultranova · · Score: 1

      My mean beaf with GC is that it makes handling all other resources a pain.

      Well... No. Java makes handling anything that isn't memory pain, but that's a Java problem, not GC problem. Having GC doesn't prevent you from having a keyword - let's call it "scoped" - which causes the "finalize()" function of an object to be called when you exit the scope it was created in. Java desn't have that, and so you end up writing try-finally -blocks, but it could be added any time Oracle feels like it.

      My second-largest beaf is that memory problems often are an indicator of poor design (you are not clear which class has what responsibility), which you loose with GC.

      I don't think having subpar programs not crashing, leaking memory, or overloading buffers all the time is exactly a strike against GC.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    154. Re:Common knowledge by ultranova · · Score: 1

      Any real GC system won't do this. You do incremental generational scavenging instead which never scans the entire heap and can actually improve paging performance.

      At least some old Java implementations did. I had a program which was okay until it hit swap; once it did, it took minutes for garbage collection to finish.

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    155. Re:Common knowledge by shutdown+-p+now · · Score: 1

      it's reasonable to doubt that C++ is faster than C.

      Idiomatic C++ can easily be faster than idiomatic C, largely because template facilities of C++ permit generic implementations of algorithms which do not lose type information, and do not require indirect function calls (e.g. compare qsort vs std::sort).

      Of course, it is perfectly possible to implement the equivalent of any particular specialization of std::sort in plain C, or even write it as a macro that is almost like a template (except that you'd have to instantiate it explicitly for every type you need).

    156. Re:Common knowledge by shutdown+-p+now · · Score: 1

      Er, the quote you use says the exact opposite of what your post says: the Java version has been optimized by an expert to achieve the performance of an unoptimized C++ version.

      (they talk about some advanced optimizations of C++ version, which apparently made it run much faster as well; but they don't count it in the tables, because they cannot provide the source code for it for others to reproduce the results - since it depends on some internal Google libraries)

    157. Re:Common knowledge by ultranova · · Score: 1

      While yes, technically that means it's assembly, not C++, the ability to drop into a low-level language for those 10 lines of high critical code means that you can easily hand optimize better than any interpreted or JIT language could ever dream. Audio decoding + SSE/MMX = Win.

      J2SE platform version 1.4.2 now uses SSE and SSE2 instruction sets for floating point computations on hardware and software platforms that support this feature.

      JITs can't dream, but the people who write them can. And are probably far more experienced with assembly than you are, for most values of "you".

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    158. Re:Common knowledge by larry+bagina · · Score: 1

      clang doesn't generate code itself, it uses llvm to actually generate the code, which is generally comparable to gcc (sometimes better, sometimes worse). Regardless, clang has better algorithms than gcc, more modular code, better design, easier to understand, etc.

      --
      Do you even lift?

      These aren't the 'roids you're looking for.

    159. Re:Common knowledge by Unoriginal_Nickname · · Score: 1

      O(1) is a subset of O(n).

      Big Oh only says anything about the upper bound. It doesn't say anything about the lower bound. Any constant-time algorithm is in O(1), O(n), O(n^2), O(2^n), etc.

      This mistake is the easiest way to figure out if someone doesn't really understand algorithms or complexity classes.

    160. Re:Common knowledge by Unoriginal_Nickname · · Score: 1

      Have you really never needed, for example, a linked data structure that could form a cyclic graph?

    161. Re:Common knowledge by Anonymous Coward · · Score: 0

      I didn't think it was possible, but it turns out there is such a thing as a malloc troll. Who knew?

    162. Re:Common knowledge by martin-boundary · · Score: 1
      C++ is not actually a superset of C, it's only approximately a superset, as there are subtle differences in the language specifications. For example, the following C code cannot be compiled by a C++ compiler:

      int *x = malloc(sizeof(int) * 10);

      There are two main reasons why C code *could* be faster than C++ code in some cases: C has looser type requirements as the above example shows, therefore C code is "less safe" and you might gain a little speed from that. The second reason is that C++ operator overloads and implicit constructors can lead to implicit slowdowns that you have no control over.

      That's not to say that C code should be considered superior to C++, it's just to expand on the idea that it is reasonable to *doubt* that C++ is faster than C across the board.

    163. Re:Common knowledge by martin-boundary · · Score: 1

      You can write C++ code that compiles into the same thing as normal C code, as you can write C code that compiles into the same thing as any variety of C++ one can think of.

      The fact that you can (which I'm not 100% sure about, btw) does not imply that you will. C++ is a much, much larger and more complex language than C (and it isn't in fact a superset, but let's ignore that). What's natural (ie idiomatic) for a programmer to write in C++ may lead to code that is significantly different than C code solving the same problem. Alternatively, the optimizer has many more language rules and requirements to satisfy when compiling C++ than when compiling C. It's a general rule of mathematics that when optimizing a function under constraints, the fewer constraints you have the better the optimized result. Either way, the point is that it's not so clear cut that C++ code beats C code.

      you can do the same hand tunning at the C++ libraries. In fact, you can do even more, but for numerical libraries it shouldn't be any difference.

      FORTRAN is a simpler language than C++. If we are talking about hand tuned libraries, then some FORTRAN code has been around for 30 years or more, it's been optimized to death and may well contain little tricks that are completely machine specific. An equivalent C++ library will have appeared much more recently, and won't have had time to be hand tuned to the same amount.

      Moreover, language issues such as aliasing are more complex in C++, causing extra optimization constraints for the compiler. That's not to say they can't be overcome, just that there's an extra handicap involved.

    164. Re:Common knowledge by ToasterMonkey · · Score: 1

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

      There are people who say things like "my car is faster than yours", and there are those who understand the many different performance metrics to rate a car by and how they interact with different track conditions. The same applies to many topics, and many things in computing for instance.

      Now, I'm not going to call you an idiot in the direct manner you might prefer, but we both know the first group of people has BY FAR the most vocal idiots.

      Thank you for your time.

    165. Re:Common knowledge by smellotron · · Score: 1

      Valgrind takes a lot longer to run any decent-sized program.

      Time well spent, my friend.

    166. Re:Common knowledge by smellotron · · Score: 1

      Have you really never needed, for example, a linked data structure that could form a cyclic graph?

      I have. No single node was "responsible" for the memory of any other node, the links were merely associations. The graph was encapsulated in a single class which was responsible for cleaning up at the end.

      In my opinion, this was a better design even if cycle-detecting GC had been available. The graph node traversal was about availability, not ownership.

    167. Re:Common knowledge by smellotron · · Score: 1

      ... aside from the efficiency gains of having at least some amount of buffer so as to not always be allocating/freeing directly to/from the OS (and I bet someone can optimize C++'s new/delete to do the same thing) ...

      This is already done, at least on Linux (and probably on other UNIXen). C++ new/delete delegates to the same "core" as C malloc/free (maybe not a direct call, but something like _int_malloc is the guts behind both). Those underlying functions only communicate with the operating system infrequently via the sbrk syscall.

      I believe "large" allocations use a separate mechanism (mmap) which involves more OS interactions, but now you're getting into optimization of the virtual memory subsystem and other dark corners. You are likely to be eaten by a grue.

    168. Re:Common knowledge by smellotron · · Score: 1

      People used to worry about ... page misses being slow ...

      Used to worry? Page misses will always matter. Memory subsystems may continually improve, but they are always competing with additional data: more media on websites, bigger caches for streamed content and TCP connections in general, higher-quality graphics and sounds in games, bigger standard shared libraries loaded, yadda yadda.

    169. Re:Common knowledge by svick · · Score: 1

      I'm curious: how would you do heap compacting with manual allocation?

    170. Re:Common knowledge by Anonymous Coward · · Score: 0

      If you knew what your code was doing, you wouldn't have to run it.

    171. Re:Common knowledge by Pseudonym · · Score: 1

      I've always felt that deallocating in a different thead should be avoided except in the very rare cases when it can't, even if it means some extra work.

      Sribe gave some good examples, but just for completeness, the last time it bit me was in a large shared cache. The thread which invalidates a cache entry is almost never the thread which made it.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    172. Re:Common knowledge by Pseudonym · · Score: 1

      There's an old saying that an assembly programmer will always beat a programmer working in a high-level language, if the assembly programmer also gets to use the high-level language.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    173. Re:Common knowledge by Xest · · Score: 1

      "That's not my experience at all, but its a few years since I was a full time C++ head."

      How many is a few? If you haven't done it since the start of the last decade then maybe that's the problem, since at least the middle of the last decade Java has been easily capable of performing as well as most C++ apps.

      "Standard java performs terribly because the whole culture encourages wasteful development"

      This makes no sense, it enforces OO principles and has much more complete libraries as standard than C++. How is that in any way a culture that encourages wasteful development? That argument makes no sense.

      "Games developers aren't developing in c++ for fun or even the cross platform issues, they're doing it because they want their games to compete with those put out by other companies."

      This is completely wrong because they can compete with managed libraries too- as I've pointed out previously, some large studios have actually used XNA and C# for arcade games (MS has XNA extensions for full arcade developers). Really, C++ is used because a) there's already a massive code investment there and decades of libraries of C++ material, and b) all consoles support it. If you truly think things like .NET and Java aren't suitable for game development you've been out of the game far too long as there are plenty of published games using them. Also, if you haven't noticed, much of the current mobile phone revolution is using managed code- yes, we're talking about devices with far more limited resources than the desktop but where managed code is far more preferable and far more commonly used.

    174. Re:Common knowledge by Pseudonym · · Score: 1

      People used to worry about memory being scarce, and page misses being slow, and caches being amazingly expensive.

      Still very much true in any kind of data-intensive application (e.g. large databases, visual effects, bioinformatics). RAM is tiny compared to the amount of data that typical modern data-intensive systems have to cope with.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    175. Re:Common knowledge by Bert64 · · Score: 1

      It comes down to the skill and available time of the programmer...

      To use a car analogy, even a bad driver with an automatic gearbox will be able to achieve the 0-60 time quoted in the manufacturer's specs, but with a manual gearbox you need to be a good driver to achieve that.. A bad driver will be faster with the automatic, while a good driver will be faster with the manual all else being equal.

      A garbage collector doesnt have as clear an understanding of the program as a good developer, and thus might waste processor cycles trying to clean up some unimportant structures while it should be processing flat out on some performance-critical logic.

      --
      http://spamdecoy.net - free throwaway anonymous email - avoid spam!
    176. Re:Common knowledge by Anonymous Coward · · Score: 0

      Adding offense to injury, plain hand-written (compiler-unoptimized) C code will beat on speed any other *portable* language (this excludes asm).

      C++, in its erratic specifications and implementation woes is far from being as portable as C - even when C++ is available on a given platform (and C is more widely available than C++ because it is... much much simpler - just look at the C/C++ ISO specs).

      When people boast about Java or PHP portability they forget that their favorite language (and libraries) were written in... C or C++.

    177. Re:Common knowledge by EsbenMoseHansen · · Score: 1

      My mean beaf with GC is that it makes handling all other resources a pain.

      Well... No. Java makes handling anything that isn't memory pain, but that's a Java problem, not GC problem. Having GC doesn't prevent you from having a keyword - let's call it "scoped" - which causes the "finalize()" function of an object to be called when you exit the scope it was created in. Java desn't have that, and so you end up writing try-finally -blocks, but it could be added any time Oracle feels like it.

      Assuming you mean a keyword used for references (variables), that would require the user to remember every time, likely leading to lots & lots of leaks. If you move it to be part of the class, you need to figure out how to handle classes that contains references to (superclasses of) this type of object.

      Solvable? Perhaps, but not so easily as that.

      My second-largest beaf is that memory problems often are an indicator of poor design (you are not clear which class has what responsibility), which you loose with GC.

      I don't think having subpar programs not crashing, leaking memory, or overloading buffers all the time is exactly a strike against GC.

      I prefer an honest crash to data corruption. So yes, I see it as a point against GC.

      --
      Religion is regarded by the common people as true, by the wise as false, and by rulers as useful.
    178. Re:Common knowledge by EsbenMoseHansen · · Score: 1

      I don't think the test would be valid for C, as they constrained themselves to work with the standard library. Anyways, C++ is not slower than C --- I don't know where that myth comes from.

      --
      Religion is regarded by the common people as true, by the wise as false, and by rulers as useful.
    179. Re:Common knowledge by ultranova · · Score: 1

      Assuming you mean a keyword used for references (variables), that would require the user to remember every time, likely leading to lots & lots of leaks. If you move it to be part of the class, you need to figure out how to handle classes that contains references to (superclasses of) this type of object.

      And if you forget to remove an object from a collection when you're done with it, it won't get garbage collected, and you get a memory leak.

      Nothing short of a compiler/runtime with superhuman AI can protect programmers from their own stupidity, but there is a difference betweeb walking a tightrope and driving a highway.

      I prefer an honest crash to data corruption. So yes, I see it as a point against GC.

      As it happens, poor design in Java typically leads to bad performance, which poor design in C leads to memory management mistakes which lead to data corruption.

      It's managed code which does a honest crash/clean exit when something goes wrong (and is not handled by the program); with unmanaged programs, you get an undefined state, and pretty much anything could happen, now or five hours later.

      Also, you may prefer crashing at the first excuse, but I prefer the programs I use to at least try to keep working (this is especially true for programs like Firefox which insist on running everything in a single instance).

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    180. Re:Common knowledge by MobyDisk · · Score: 1

      Thank you. That was the best, most salient answer I've heard on this subject. I was totally geared up for a reply stating that the C++ supports some particular O-O feature, and therefore all C++ code is slow because of it.

    181. Re:Common knowledge by EsbenMoseHansen · · Score: 1

      Assuming you mean a keyword used for references (variables), that would require the user to remember every time, likely leading to lots & lots of leaks. If you move it to be part of the class, you need to figure out how to handle classes that contains references to (superclasses of) this type of object.

      And if you forget to remove an object from a collection when you're done with it, it won't get garbage collected, and you get a memory leak.

      Nothing short of a compiler/runtime with superhuman AI can protect programmers from their own stupidity, but there is a difference betweeb walking a tightrope and driving a highway.

      Let me try an example. Does EsbensFooClass contain a resource that should be collected as soon as possible? If it doesn't, will it in the next version of the library? The keyword simply puts the burden in the wrong place. The class is the one who knows about it's resources, the class should be the one who decides when resources must be reclaimed. That was my point, and why it is an error-prone method. C++ steps around this by essentially requiring every class to reclaim it's resources as "soon as possible", for some value of possible.

      Also, you may prefer crashing at the first excuse, but I prefer the programs I use to at least try to keep working (this is especially true for programs like Firefox which insist on running everything in a single instance).

      Well, it depends. For a browser, I agree.. keeping running is probably the better behavior, since any corruption probably won't cause harm in the future. But not so for a spreadsheet program.. if I save my corrupted document, overwriting the last version, I could very well have to go back to the mythical backup to reclaim some of my work. With the crash, I'd probably have an autosave, or at least the document before I started out.

      All this is somewhat hypothetical.. in the practice, I find that either system almost uniformly just crash (one with a core dump, Java with just a backtrace), leaving the user with a dataloss since the last (auto)save.

      I have skipped over the security aspect. For programs facing potentially malicious data, like say a DNS server, I think the overhead and price of managed memory is perfectly reasonable. There, of course, Java is also useless due to its poor support for fork() and other process handling machinery to properly shield against malicious data, but other managed languages might do better.

      --
      Religion is regarded by the common people as true, by the wise as false, and by rulers as useful.
    182. Re:Common knowledge by malsbert · · Score: 1

      NO!

      as you say: "Big Oh only says anything about the upper bound. It doesn't say anything about the lower bound."

      the upper bound of a O(1) algorithm is NOT O(n).

      --
      "Men will never be free until the last king is strangled with the entrails of the last priest." - Denis Diderot.
    183. Re:Common knowledge by Douglas+Goodall · · Score: 1

      There it is. :-) I have been programming in C++ from the beginning. I have never had problems with heap fragmentation, probably because I make heavy use of automatic variables (and classes). When the scope closes they are gone, but I see the hinge point. Sometimes I manage my class instantiations manually by declaring a pointer to a class, then using new to instantiate it. This has the benefit of allowing me to use delete and know my destructor will be run right now, instead of in some non-determined manner at the end of the scope with other automatics as well. I just cannot swallow the concept that an interpreted language is going to run faster than a native code generating C++ compiler. Given run-time libraries of equal quality, there is no ignoring the overhead of the VM, GC notwithstanding. We all have moments when we want to hack out a quick program/script, and I think programming in Python is fun, but I don't spend a moment wondering which kind of code is faster in execution. I know the classic discussion about shorter development time inversely proportional to faster execution time. When I have to collect sensor data from rack of instruments instruments in a fraction of a second, I don't have the time to spare for garbage collection. This has always been a problem for me that I write real-time code, and you cannot write effective real-time code when you are subject to indeterminate delays at indeterminate times. The name itself, "managed code", gives me the willy nillies.

    184. Re:Common knowledge by SanityInAnarchy · · Score: 1

      But not necessarily as cheap as just assigning the pointer.

      Worse than that, it's at least one extra instruction, and one which is repeated often. Probably inlined, because actually making any sort of call is going to take at least as much space as incrementing/decrementing.

      Which means your code is now bigger everywhere. Which means more cache misses. You probably get smoother, more consistent performance, but probably not overall better, and there aren't that many places this particular bit of consistency matters.

      However, I don't agree that reference counting has so many drawbacks as to not be useful. I don't know of many other mechanisms for GC other than manually using malloc/free/new/delete as appropriate which can deliver quite the consistency of reference counting -- the instant nothing has a reference to the object anymore, it goes away and its destructor is called. This is one thing I miss from C++ in languages which do have builtin GC -- it's actually nicer semantics.

      For example, in Ruby, I can do this:

      open 'foo', 'w' do |file|
        file.puts 'Hello, world!'
      end

      This guarantees the file is closed, which is helpful when file descriptors are limited, or when I just want to be sure that everything's properly flushed to disk. But I have to do it in that block format, which is occasionally inconvenient, and my only other option is to either manually close the file or let the file maybe be closed by garbage collection at some point -- but finalizers aren't guaranteed to ever run before the program itself eventually closes, and it's hard to imagine a good way to catch errors from that, so no, bad idea.

      By contrast, in C++, we can do this (grabbed from a quick Google search; it's been awhile since I've done C++):

      ofstream myfile("foo");
      ofstream << "Hello, world!" << endl;

      And as soon as the object falls out of scope, the file will automatically be closed. The thing I like about reference counting, though I can imagine there might be more efficient ways to do it, is that I can do something like this:

      shared_ptr<ofstream> myfile = new ofstream("foo");
      (*myfile) << "Hello, world!" << endl;

      Only this time, I can pass that shared_ptr around -- the file will now automatically close when the last reference to it falls out of scope.

      Sure, there are limitations. Sure, 99% of the time, I'd much rather have the advantages and limitations of real GC. But I think that's an example of where reference counting is still useful.

      --
      Don't thank God, thank a doctor!
    185. Re:Common knowledge by Darinbob · · Score: 1

      Don't confuse GC for memory and GC for other resources. It does not matter if memory is freed immediately. Applying GC semantics to files should be done as a "oops" safety net and not as the primary way of dealing with files, if you forget to close or catch it then it's an error. This capability is only there in GC systems because it's the only way to clean stuff up if the program doesn't do things correctly, especially in things like Smalltalk which maintain a long term memory image. Reference counting may work great for files but it doesn't mean reference counting is great for garbage collection with memory.

    186. Re:Common knowledge by marcosdumay · · Score: 1

      That is right, I said it wrong. You'd have to replace malloc. I just wanted to say that you can do that.

    187. Re:Common knowledge by Unoriginal_Nickname · · Score: 1

      YES! O(1) is a subset of O(n), and I will give you a formal proof of this fact.

      Recall, by definition, a function f(x) is in O(g(x)) iff there exists c positive real number and x0 real such that for all x>x0 |f(x)|<=c|g(x)|.

      PROOF: Let f(x) be any function in O(1). By construction, and the above definition, there exists satisfactory c,x0 such that for all x>x0 |f(x)|<=c|1|=c.
      Let x1 = max{x0, 1}. n.b. x1>=x0 and x1>=1. It follows that for all x>x1 |f(x)|<=c<=c|x|. Therefore, there exists c positive real number and x1 real such that for all x>x1 |f(x)|<=c|x|. Therefore, by definition, f(x) is also in O(n).

      f(x) in O(1) implies f(x) in O(n). This is the definition of a subset! O(1) is a subset of O(n).

      Q.E.D.

      Indeed, any algorithm in O(1) is also in O(n).

    188. Re:Common knowledge by Sam+Douglas · · Score: 1

      Well, you'd just allocate a block of memory and write an allocator that returns 'handles' which can be updated when the memory is compacted. See, no garbage collector needed. /facetious

    189. Re:Common knowledge by Sam+Douglas · · Score: 1

      A good garbage collector already has memory set aside to allocate new objects in. No searching is required, just like allocating memory on the stack.

      When the pool of memory for that gets full, the live objects are copied to a new location and the entire memory pool is emptied.

      The "generation 0" collection is normally pretty painless, as most objects are short-lived anyway.

    190. Re:Common knowledge by malsbert · · Score: 1

      Damn, you got me :(

      I here by swear; From this day forth, I shall define insert/remove on a list to be linear in time!

      Ps: since you allow n to be a fraction; How many steps do you need to insert an element in a list with 2.5 elements?

      --
      "Men will never be free until the last king is strangled with the entrails of the last priest." - Denis Diderot.
    191. Re:Common knowledge by Unoriginal_Nickname · · Score: 1

      Big-Oh notation comes from real analysis, which is why the definition is given over functions with a real domain. Having potentially-real 'n' is also needed for certain important results in CS, such as the Smoothness Rule and the Master Theorem.

      It's easy to see that the discrete case does not contradict the general definition: if the relation in the definition is true for some fractional x0, it must also be true for the natural number ceil(x0).

      With respect to your oath, you shouldn't say that list insertion is linear in time, because it's untrue. :P "List insertion is O(n)" does not mean the same thing as "List insertion is linear in time." It roughly means "List insertion is not slower than linear in time." You need to use Big-Theta notation if you want to be precise when you're talking about algorithms.

      You shouldn't feel bad about not understanding what Big-Oh means. Most people misuse it on the internet, so it may be difficult to learn correctly. You should be aware, though, that not knowing the differences between Big-Oh, Big-Theta and Big-Omega is a sign of an extremely weak background in theory. If you're interested in learning, at this level I usually recommend 'Introduction to The Design & Analysis of Algorithms' by Anany Levitin.

  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 Tablizer · · Score: 1

      I thought Pascal should be included, and I bet it would make a pretty good showing.

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

      rick-roll.

    3. Re:Sensationalism at its finest by Anonymous Coward · · Score: 0

      Assuming the program was written similarly, the speed would be very close to the same. If it did a lot of fancy pointer stuff that is difficult to do in Pascal, C might end up faster. 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).

    4. Re:Sensationalism at its finest by Anonymous Coward · · Score: 0

      eventually the cpu has to do this.. I don't see how any language could get around it. searching through strings is a necessary evil.

    5. Re:Sensationalism at its finest by Anonymous Coward · · Score: 0

      Pascal strings are prefixed with the string length instead of being null-terminated, so looking up the length is O(1).

    6. 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.

    7. Re:Sensationalism at its finest by Anonymous Coward · · Score: 0

      Every know and then yes. But you can cache the length in an object variable ... like ... pascal ...

    8. Re:Sensationalism at its finest by mikael_j · · Score: 1

      Well, without speaking specifically about Pascal and C/C++ there is the simple matter of how the strings are dealt with. While with one language creating a string and storing it in memory may very well mean that the program just allocates enough memory and dumps the string there with another language the string stored in memory might come with some form of metadata/properties, so rather than having n bytes allocated to your string and being forced to scan through it looking for the null byte you know that, as a hypothetical example, the first eight bytes of memory allocated for the string are a 64 bit number that gives the exact length of the string. Of course, it all depends on what the program is doing with the data.

      --
      Greylisting is to SMTP as NAT is to IPv4
    9. Re:Sensationalism at its finest by jd · · Score: 1

      I agree. The article is nonsense. Whilst one of the comments suggested comparing it to assembly, that's perhaps a bit unfair. However, to be a test of "languages on the market" I would have expected the following to be there for certain:

      • C99
      • D (Digital Mars' language)
      • Fortran 2008
      • Erlang
      • Forth

      Now, if you want to consider "the best", then you'd also want to include a few of the more experimental languages:

      • Occam-Pi
      • Unified Parallel C
      • AspeCt-oriented C
      • NESL

      The problem with selecting benchmarks is that it's easy to pick languages your favourite language will do better at. The challange is to use a wide enough range of methodologies that you cannot predict ahead of time which one will do best at what.

      --
      It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
    10. Re:Sensationalism at its finest by AHuxley · · Score: 1

      Ada too :)

      --
      Domestic spying is now "Benign Information Gathering"
    11. Re:Sensationalism at its finest by Anonymous Coward · · Score: 0

      I don't understand all the negativity. The claim that "C++ is the clear winner" might be a bit much, but the article isn't nonsense since it orders 4 languages. You're saying they should have compared 5 or 9 more. Fine, they could have compared 13 languages. That doesn't make the article "nonsense" or a "non-story", it still got 4/13 of what you want.

    12. Re:Sensationalism at its finest by Anonymous Coward · · Score: 0

      I agree. The article is nonsense. Whilst one of the comments suggested comparing it to assembly, that's perhaps a bit unfair. However, to be a test of "languages on the market" I would have expected the following to be there for certain:

      • C99
      • D (Digital Mars' language)
      • Fortran 2008
      • Erlang
      • Forth

      Now, if you want to consider "the best", then you'd also want to include a few of the more experimental languages:

      • Occam-Pi
      • Unified Parallel C
      • AspeCt-oriented C
      • NESL

      The problem with selecting benchmarks is that it's easy to pick languages your favourite language will do better at. The challange is to use a wide enough range of methodologies that you cannot predict ahead of time which one will do best at what.

      RTFP. It is not explicitly expressed, but they tested OO-capabilities with built-in objects, loops over collections and data structures (although lists is lacking in GO, C++ lacks a built-in lopp-over collections statement and all data structures used have easy to find, good and free, implementations in C and many other languages). But I wonder why they didn't test Objective-C or Vala; with these specific test conditions these two languages would likely kick C++ ass. Objectives-C:s object creation process gets faster then C++:s in long loops and Vala is generally faster then C++, as long as you don't use any horrible tricks in C++ that require extensive knowledge of what assembler/machine instructions the compiler in use generate.

    13. Re:Sensationalism at its finest by MadKeithV · · Score: 1

      >

      BTW, one subtle difference between C and C++ is in templates.

      Subtle, yes, if "a turing-complete sub-language" is considered subtle :-)

    14. Re:Sensationalism at its finest by FlyingGuy · · Score: 1

      Delphi would be able to go head to head with C++. It will lose but the time difference will be marginal. The compiler and linker and pretty amazing and blindingly fast. It would be interesting to see and out of the box ( build with defaults) competition between the two as I think Delphi would win with ease.

      I hate Anders for defecting to the Evil Empire. Say what you like about C# but that is another in a long line of huge achievements that man has to his name.

      And least anything poo poo Delphi look around, there are a lot of major applications authored in that version of pascal.

      --
      Hey KID! Yeah you, get the fuck off my lawn!
    15. Re:Sensationalism at its finest by Anonymous Coward · · Score: 0

      Fortran 2008?

      What Fortran-2008 compliant compiler would you test it against?

    16. 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
    17. Re:Sensationalism at its finest by TheRaven64 · · Score: 1

      Iteration loops in Objective-C 2 are very fast. If you iterate over an immutable array then you have one message send to get a pointer to the C array and then an inner loop (which the compiler will typically unroll) to scan across it. If you iterate over a mutable collection, then the outer loop will copy 16 object into an on-stack buffer with a single message send. All of this is hidden from the programmer inside the for..in syntax. With the GNUstep runtime, we can cache the message lookup, so the cost is about the same as a C function call. If you turn on the profile-driven stuff, then we can even speculatively inline the message send, so it becomes about as fast as iterating over a C array in the common case, but still works (slower) if you pass some other array object type in a few times.

      --
      I am TheRaven on Soylent News
    18. Re:Sensationalism at its finest by Anonymous Coward · · Score: 0
    19. Re:Sensationalism at its finest by Short+Circuit · · Score: 1

      Perhaps this data would be more interesting.

    20. Re:Sensationalism at its finest by Short+Circuit · · Score: 1

      My guess is that they wanted to do comparisons between the most common and developer-popular languages with strong typing and strong object models. That reflects an investment in those particular design idioms. Selecting for language features will narrow the field somewhat.

    21. Re:Sensationalism at its finest by jd · · Score: 1

      No, because they tested a very narrow range of OO that was likely selected to make C++ the clear winner. Ok, go ahead and test 12 significantly different types of OO - they're not all the same - and see what happens. The nonsense is because they picked too narrow a grouping to draw any conclusions. Was it the language that was better? That specific compiler? The level of experience of the developers in each? Would other OO languages have done much better than C++?

      --
      It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
    22. Re:Sensationalism at its finest by Estanislao+Mart�nez · · Score: 1

      However, to be a test of "languages on the market" I would have expected the following to be there for certain [...]

      Who claimed the paper was a test of the "languages on the market"? (Hint #1: that was not a rhetorical question. Hint #2: you're supposed to draw a conclusion from the answer.)

    23. Re:Sensationalism at its finest by Anonymous Coward · · Score: 0

      They're mostly languages that Google uses. The only other primary language they use is Python.

      You think Python is faster than C++? It's not even faster than other scripting languages.

    24. Re:Sensationalism at its finest by jd · · Score: 1

      From TFA:

      Google has released a research paper that suggests C++ is the best-performing programming language in the market.

      Seems pretty obvious that there was indeed a claim that C++ is the best-performing language in the market. I tried drawing a different conclusion from this but the pencil broke.

      --
      It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
    25. Re:Sensationalism at its finest by jd · · Score: 1
      --
      It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
    26. Re:Sensationalism at its finest by MikeBabcock · · Score: 1

      You missed LISP, Python and *wretch* PHP.

      --
      - Michael T. Babcock (Yes, I blog)
    27. Re:Sensationalism at its finest by jd · · Score: 1

      LISP perhaps should be there, as it runs damn fast on any stack machine. Tcl/Tk, Perl, Python, Ruby and PHP are not designed to run fast and, by being script languages, can't be fairly compared to compiled languages.

      --
      It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
  3. More languages. by miffo.swe · · Score: 1

    This had been much more fun if there had been more languages and compilers benchmarked. Really interesting read though.

    --
    HTTP/1.1 400
  4. ... 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 drolli · · Score: 1

      they should have included fortran IMHO.

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

      What do you suggest then? Assembly?

    3. Re:... and? by Vintermann · · Score: 1

      On a single algorithm! I hope it was a good one.

      --
      xkcd is not in the sudoers file. This incident will be reported.
    4. 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.

    5. Re:... and? by whiteboy86 · · Score: 0

      >C++ is the fastest. Is this seriously a surprise to anyone?

      Sure it is, lots of managers have been brainwashed to the point of Java evangelism. Sun corporation and others tried very hard to push their corporate agenda languages and also trying to discredit C/C++ in the process, sadly nothing important has been ever written in them and those who fall for this are still fixing their code, slowness, portability after-issues, garbage collection stalls and other funny nightmares it gave them. IEEE/ISO multiple times rejected them for some good reasons, but one in particular, corporate lock-in.

    6. Re:... and? by maxwell+demon · · Score: 1

      Well, let's look at their list:
      * C++: compiled to machine code, doesn't have GC.
      * Go: compiled to machine code, does have GC
      * Java, Scala: compiled to bytecode, does have GC.

      So except for the bytecode/GC combination, each class has only one language inside.
      For machine code/no GC, they should at least have added Fortran (which is often considered the fastest for numerics; it would be interesting if that claim still holds).
      For machine code/GC, they could e.g. have added D.

      And of course they should have tested with a set of algorithms representing different types of algorithms (I guess the performance characteristics differ greatly whether you look e.g. at numerics or string handling).

      --
      The Tao of math: The numbers you can count are not the real numbers.
    7. 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.

    8. Re:... and? by jd · · Score: 1

      If I'd assigned someone a project like that, I'd have mandated a minimum of 12 languages (4 popular, 4 traditional, 4 experimental) with a further breakdown mixing various methodologies (you want some parallel languages, some functional, some procedural, some stack, some OO, and maybe some with more exotic forms of abstraction).

      My suspicion is that C++ will rank good against some, not so good against others, but where the balance shifts according to what you're trying to do.

      Now, if you're insisting on pure OO vs OO, then the same 4:4:4 breakdown applies (where traditional might include a Smalltalk variant or spinoff). OO hasn't followed a linear path from then to now, it has branched in many directions and is still branching today. You've got to have a sensible analysis of then, now and future, to know how a language truly rates at any given task.

      --
      It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
    9. Re:... and? by beelsebob · · Score: 1

      Better yet, throw in Single Assignment C, and then run the heavy number crunching on a machine with many cores/cluster and see what happens.

    10. Re:... and? by Anonymous Coward · · Score: 0

      How about we start with ICC, GCC, PGCC, and Clang. And that is just to get started with implementations of C++. (Languages are not efficient. Implementations of languages are efficient.) Then we can move on to Chez Scheme, Ikarus Scheme, PLT Scheme (aka Racket), GHC Haskell, SML, MLton, and OCaml, as well as various implementations of common lisp, Fortran (with and without BLAS/LAPACK), Pascal, Erlang, etc.

      The bottom line is that the paper was not rigorous and has about the technical quality I'd expect from one of my undergraduates (too many uncontrolled variables). As a paper reviewer (which I have been but not for this paper), I'd have to strongly reject the paper as it provides no useful, meaningful information due to its lack of rigor.

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

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

    12. Re:... and? by MemoryDragon · · Score: 1

      Not really, if they compared C++ with C or Assembler it would look differently.

    13. Re:... and? by sim82 · · Score: 1

      It is relevant, because Java (especially the SUN hotspot VM, so this includes scala) must have been the most ambitioned attempt to create a fully hw-independent, garbage collected and jit-ed "language platform" ever. Java is the best representative for any comparison of "non-native" vs. "native". Still, contrary to what has been claimed, in most cases you can only achieve "sub-native" performance (especially when you consider that the java vm, by design, makes it impossible to directly exploit stuff like SSE, which can have a huge impact).

    14. Re:... and? by AmiMoJo · · Score: 1

      A lot depends on the compiler and CPU. Intel C compilers are optimised for Intel CPUs, and I wouldn't be surprised if even with open source compilers there were significant differences between architectures. There certainly is with OpenCL - some applications run much faster on nVidia hardware, others (like password cracking) are generally faster on ATI GPUs.

      --
      const int one = 65536; (Silvermoon, Texture.cs)
      SJW, n: "Someone I don't like, and by the way I'm a fuckwit" - AC
    15. Re:... and? by Anonymous Coward · · Score: 0

      I am not sure if you are sarcastic or not. But in reality Fortran95 is much faster than C++ (and Fortran77 is marginally faster than C). More specifically I have tested them in Linux and Windows XP with GNU compilers, with applications of genetic algorithms, which are not exactly number crunching.
      Disclaimer: I teach Fortran.

    16. 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
    17. Re:... and? by TheRaven64 · · Score: 1
      Greenspun's tenth rule of programming:

      Every sufficiently complicated C++ program contains an inefficient, badly specified, implementation of half of Common Lisp

      In the more general case, using an ad-hoc reimplementation of one language in another is rarely faster than just using the language directly.

      --
      I am TheRaven on Soylent News
    18. Re:... and? by TheRaven64 · · Score: 1

      Depends on the project size. Most of the projects I regularly hack on are over 300,000 lines of code. Can you name even one assembly project that's this level of complexity? C projects at this level tend to use a poorly-performing ad-hoc implementation of either Smalltalk or Simula object models, depending on the preferences of the developers (or, in some cases, two or three completely incompatible object models). C++ projects this complex implement an ad-hoc dynamic dispatch mechanism, that generally performs significantly worse than the stock implementation in a language like Lisp or Objective-C. Programs in any language that doesn't have GC implement their own ad-hoc GC, usually based on reference counting and either leaking cycles or with an inefficient ad-hoc cycle detector.

      --
      I am TheRaven on Soylent News
    19. Re:... and? by GreatBunzinni · · Score: 1

      OpenGL and OpenCL are not programming languages. They are APIs, which happen to be available on multiple languages. Trying to bundle APIs such as Open{GL,CL} with programming languages such as C, C++ and even Assembly is a public demonstration of your ignorance.

      --
      Slashdot, fix your code or at least hire someone who is competent at it to do it for you.
    20. Re:... and? by Anonymous Coward · · Score: 0

      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.

      Err yeah but there's nothing that can be done in any language that outperfoms an equivalent done in C and (if needed) inline ASM. Using C++ was easier/faster than optimizing OO-style C... it was probably the correct choice in that situation. It's not going to outperform a re-engineered and optimized C program though.

      I suspect you know this since you added the disclaimer and noted an observation instead of forming a conclusion. Still, I see such errant conclusions presented all the time. Simply because we can write comically inefficent C algo that runs slower than an optimiszed version in interpreted javascript -- a conclusion that javascript is "faster than C" is nonsense.

    21. Re:... and? by Anonymous Coward · · Score: 0

      Stanley B. Lippman writes, in "Inside the C++ Object Model", that such a test was done.

      From memory, Fortran was twice as fast, until the C++ code was optimized to reduce temporaries. After that, the C++ code performed as well as the Fortran code.

      I don't have the book in hand at the moment, so can't give more details.

    22. Re:... and? by Anonymous Coward · · Score: 0

      Forget Go and Scala... the important thing to take from this shootout is that C++ BEAT JAVA!!

    23. Re:... and? by realityimpaired · · Score: 1

      He may have meant putting in API calls in the program they're benchmarking as a test of how well the compiled program communicates with external libraries that may or may not be done in a different language... but I don't see how that would make for a valid benchmark, since there's system-level bottlenecks in place that could artificially fudge any results you're getting.

      As for why he would put Assembly in the same category... maybe he meant switching to inline assembly in your code? I dunno. Proper native complied ASM should be significantly faster than a higher level language, though it does have to be written specific to the hardware it's being run on (instead of just being compiled for it), which can turn people off. If you're going to include ASM in a benchmark against Java, you may as well write something in machine code/hex and compare that for speed, too, though...

    24. Re:... and? by Anonymous Coward · · Score: 0

      GLSL

      The SL stands for Shader Language. It's the programing language you write Vertex, Pixel and Geometery shaders in.

      Half of OpenCL is an API designed to allows you to run the other half of OpenCL, which is a programing language designed similar to C but different, on CPU, GPU and other parallel computing hardware.

    25. Re:... and? by FFOMelchior · · Score: 1

      Wow, they compared a whole four languages: C++, Java, Go and Scala[...]

      Yeah, can't believe they didn't include LOLCODE...

    26. Re:... and? by Anonymous Coward · · Score: 0

      Read the comments. It IS a surprise to a lot of readers. A lot of them are posting reasons why speed doesn't matter so they can justify the decision they've already made.

    27. Re:... and? by iluvcapra · · Score: 1

      That's not fair, object orientation isn't strictly a language feature, it's also a generic pattern. Gobject is a C library but is object-oriented. Most object-oriented scripting languages are implemented in an underlying object-oriented C. Method(object, arg1, ...) and object->Method(arg1, ...) are equivalent, particularly if object is an opaque type not in the header.

      We could even cite the crazier case of Objective C or Objective J[avascript], where every method call becomes a call to a runtime of msgSend(object, methodNumber, args...).

      This seems like a total hackaround to force a language into a box it wasn't meant to fit in, though in the case of Objective-C, objc_msgSend() is implemented in a few dozen lines of ASM and can be compiled to a direct dispatch for the non-dynamic case.

      --
      Don't blame me, I voted for Baltar.
    28. Re:... and? by TheRaven64 · · Score: 1

      Before you try to explain how Objective-C works to me, I should point out that I'm the author of the GNUstep Objective-C runtime and the maintainer of GNU runtime code generation in LLVM / Clang, as well as the designer and author of several optimisations that eliminate dynamic lookup cost in Objective-C...

      --
      I am TheRaven on Soylent News
    29. Re:... and? by iluvcapra · · Score: 1

      Oh, that's right. I knew that, I just didn't look at the author name.

      I've always had this sort of irrational hostility to that Greenspun law, it seems to encapsulate everything I hate about developer over-generalization, in a smug language-weenie wrapper.

      --
      Don't blame me, I voted for Baltar.
    30. Re:... and? by Jonner · · Score: 1

      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?

      They didn't include several language implementations which perform better than Go according to The Computer Language Benchmarks Game, such as SBCL and GHC. They didn't even include C, which is far simpler than C++. Unless one restricts herself to the C subset of C++, she'll probably always have more overhead for things like method calls.

  5. 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: 0

      I disagree. If you know and understand computers, c++ is fairly easy as it doesnt obfuscate things the way java does. If you dont know what bitbanging is, never tried memory debugging or find the concept of "pointers to pointers" confusing you are better off with java, but pros should know their c.

      I have worked with c/c++ for the last six years, and Ive never seen anyone use much java in the oil/gas industry (Applets not included).

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

      If you can't figure out how to free memory that you've alloc'd, please stop programming as you suck at it.
      I've been a professional programmer for over 20 years and of all the programmers I have worked with only the shitty programmers can't figure it out.

      It's just not that hard.

    6. 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)

    7. Re:C/C++ faster but produces more bugs by msclrhd · · Score: 1

      And in C#/Java it is easy to not cleanup a resource by not closing/destroying the resource -- not placing it in a try...finally or using block.

      Or, to use your examples, in C#/Java it is easy to create bugs by not properly trapping a NullPointerException or ArrayOutOfBounds exception causing the program to close unexpectedly!

      I'm not saying that C/C++ are simple, or that they are not error prone, just that you need to be careful in all languages you program in. Any program has bugs in it.

    8. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 1

      Jeez, your code must not do anything interesting if you don't use memory.

    9. Re:C/C++ faster but produces more bugs by msclrhd · · Score: 0

      Use shared_ptr (Boost, C++TR1 or C++0x) for single objects to manage their lifetimes. Use std::vector, std::list or another suitable container for arrays/lists of objects. Use RAII classes for other resources.

      Automatic memory management/garbage collection does not cover resource management. Consider the following in Java/C#:

      public void foo()
      {
            File f = new File('somefile.txt');
      }

      The garbage collector will correctly clean up the memory, but not the resource, so you need to do something like:

      public void foo()
      {
            using (File f = new File('somefile.txt'))
            { // ...
            }
      }

      In C++, the file object will be correctly scoped. If you wanted to create a file object for use elsewhere in a place where a generic device could be used, you can write:

      std::tr1::shared_ptr create_file(const char *filename)
      {
            return std::tr1::shared_ptr(new file(filename));
      }

      void foo()
      {
            std::tr1::shared_ptr f = create_file("somefile.txt"); // ...
      }

      no need to worry about freeing up the memory or the resource as the code will do that for you (shared_ptr and file respectively).

    10. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      Apparently the last time you've used C++ was in 1998. Arrays, manual memory management, buffer overflows, memory leaks, resource tracking, allocation waste haven't been issues in a very long time except for in language-feature-constrained corporate environments.

      C++ has many much more serious problems hurting it but those aren't among them.

    11. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      I'd rather have my program crash with an uncaught exception that be the entry point for a compromise

    12. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      if you start adding helper stuff from other languages to c++, it bogs it down. there's no way around that.

    13. Re:C/C++ faster but produces more bugs by Luna+Argenteus · · Score: 1

      Meanwhile in Finland, Linus Torvald is writing one of the very rigorous stuff that is the Linux kernel mainly in C and some critical parts in Assembly.

    14. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      I guess you never heard of the the C++ standard library or any other modern C++ libs. Current best practice is that, except in specific situations like legacy or very high performance code, you do not manage memory manually. And why would you? There's tons of classes like std::vector, list, unique_ptr, shared_ptr as well as tons of libs to handle it for you in a fail-safe and flexible manner.

      Consequently used modern C++ doesn't behave any different from a GCd language. You never have to worry about memory. You just use it.

    15. Re:C/C++ faster but produces more bugs by maxwell+demon · · Score: 1

      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.

      If you have problems managing your memory in C++, you must not have heard of RAII. Or of container classes.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    16. Re:C/C++ faster but produces more bugs by j_sp_r · · Score: 1

      And if you want to do bitbanging (or low level rs232 communication for that matter) and realtime programming Java makes you want to pull your hairs out. Don't start on JNI. Although developing anything high-level is much easier than c++.

    17. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      Not using 'exposed' heap is not the same as not using memory. Use containers instead. Heap is such terrible low-level concept...

      Here you have some examples of C++ code written this way: http://www.ultimatepp.org/www$uppweb$examples$en-us.html. Some of them are quite complex.

      No heap needed. And code usually gets simpler than in Java...

    18. 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.
    19. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      Add std::array, std::aligned_storage (both used for stack allocation), stack-based allocators, etc.

    20. Re:C/C++ faster but produces more bugs by MadKeithV · · Score: 1

      C++ will always necessarily be faster to execute

      It may be unintuitive and a mostly academic argument, but you are wrong - C++ is always necessarily compiled to a set of specific hardware targets which may be sub-optimal for the actual hardware the program is executed on. A JIT-compiled language can target the actual machine you are running on, enabling more specific optimizations. A JIT-compiled program may also end up running faster than before as the JIT-compiler is upgraded, on the same machine, without any action of the original program developer.

    21. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      Are you sure you didn't write this diatribe about C? Because the problems you state have more to do with C and less to do with C++. Memory management in C++ is really far less tedious than it is in C. But in 99% of the cases, it's not that difficult in C either. It only becomes difficult when the ownership of a pointer is unclear. C++ solves this with shared_ptr and other smart pointers (which are not at all the same as a Java-style sweeping GC)

    22. Re:C/C++ faster but produces more bugs by Alex+Belits · · Score: 1

      I can assure you, those things have absolutely nothing to do with someone "having problems" with memory management. If you do it wrong, you will still do it wrong regardless of tools, features, methods and ideologies involved. The point is, you have to understand what you are doing, not choose the tools or follow the instructions that supposedly will do it for you.

      --
      Contrary to the popular belief, there indeed is no God.
    23. Re:C/C++ faster but produces more bugs by Alex+Belits · · Score: 1

      Any given programmer ALWAYS produces a constant (amount * severity) of bugs per time.

      --
      Contrary to the popular belief, there indeed is no God.
    24. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      Yeah, right - because only one language should be used for everything. Java is good for apps which want to run on multiple platforms. C/C++ is good for high performance server apps, particularly those that need to deal with large amounts of data (where memory management/layout is king for performance). C/C++ is also king for embedded apps which need small footprints and controllable memory usage.

      Honestly - how many more times are we going to have to listen to religious arguments about languages? They're just tools, And like all tools, no one tool is always right. You match the tool to the job.

    25. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      Aside from the fact that this is not "helper stuff from other languages" (this is C++ we're talking about, this is a unique property of C++, and with C++0x things like shared_ptr are even in the standard now!)... You're wrong.

      The thing is, in many instances the cost of using the RAII idiom is zero. The destructor gets inlined and if you were coding in straight C you'd have had "cleanup" code anyway that closes the file or frees the buffer, so this isn't any extra code. Also, unlike a "lesser" language like Java, you don't have need a virtual call at every method. Add templates to this equation and you can do a lot of amazing things without compromising flexibility at the source level.

    26. Re:C/C++ faster but produces more bugs by maxwell+demon · · Score: 1

      Of course you have to understand what you are doing. But that's true in any language. Yes, you can also leak memory in Java (not in the strict sense that there's no reference to it, but in the weaker sense that it is still referenced, but there's no program path which will ever access it again, and thus it should be discarded).

      --
      The Tao of math: The numbers you can count are not the real numbers.
    27. Re:C/C++ faster but produces more bugs by Alex+Belits · · Score: 1

      but there's no program path which will ever access it again, and thus it should be discarded

      Memory management does not work that way (also lol halting problem).

      --
      Contrary to the popular belief, there indeed is no God.
    28. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 1

      You should not "trapp" NullPointer or ArrayOutOfBounds.. They should terminate your program and produce a stacktrace, the bug can then easily be fixed. If you do trapp these exceptions you should really know what you are doing, cause you are in the domain of ignoring seriously errors.

      Regarding C/C++ you get errors that does not show up at ones, or terminate your program by SegFault at the point where Java would have produced NullPointer or ArrayOutOfBounds. So same effect as not catching the Exceptions in Java.. Program terminates, only in Java it points to what went wrong, C/C++ says nothing about the error.

      Java is a OO "Visual Basic" language, easy to understand, hard to do really wrong in, with the penalty that you as a developer can not optimize for a specific hardware. Both C and C++ can be written with a specific hardware in mind, you can forget this in Java.

      Someone else wrote for years ago, and it says it all:
      "Java is extremely portable. A Java application can be run anywhere someone wrote a VM for it in C or C++"

      Regards,
      A Java developer.

    29. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      Programmer time may be more expensive than computer time, but it's not more expensive than user time, and when the user is sitting there staring at a progress bar, you are using their time. As the user of your program, I'm perfectly willing to pay for my fair share of your programmer time so that your program doesn't waste my time.

    30. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      I am not OP anonymous coward, but for I can say this: Yes, sometimes I have memory problem in C++. Like 3 or 4 times a year. So the problem exists, but it is much much less serious than GC proponents attempt to claim.

      Then, C or "traditional" C++ code is completely different kind of game, I agree. But in modern C++, it is non-issue. You will leak more resources in Java by forgeting finally blocks than memory in modern C++...

    31. Re:C/C++ faster but produces more bugs by jeremyp · · Score: 1

      You shouldn't be trapping either of those exceptions. They are both indicative of an incorrect assumption on the part of the programmer which means that the program's state is no longer trustworthy. The only safe thing to do is get out and start again.

      --
      All I want is a secure system where it's easy to do anything I want. Is that too much to ask ~~ Randall Munroe
    32. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      That's true of reference counting (shared_ptr), not unique_ptr/scoped_ptr, std::array, vector or similar which compile to equivalent C code.

    33. Re:C/C++ faster but produces more bugs by Pseudonym · · Score: 1

      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.

      You've clearly never programmed in C++. Or, more likely, all of your C++ code has been C code in a very thin disguise.

      --
      sub f{($f)=@_;print"$f(q{$f});";}f(q{sub f{($f)=@_;print"$f(q{$f});";}f});
    34. Re:C/C++ faster but produces more bugs by kikito · · Score: 1

      It's not that I can't figure it out. It's that I don't *care*.

      And a lot of programmers shouldn't. It's a perfectly automatizable problem that can be done by the machine itself. In most cases it's just inefficient to do that manually. You might as well be writing the machine code yourself.

      Granted, there are some cases in which it's necessary to manage memory by hand. But those are the exception, not the norm.

      If you are spending time figuring out the memory that all your programs are allocating, chances are that you are an inefficient programmer - and you don't know what is important in programming.

    35. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 1

      And no more forgetting to free that memory afterwards, resulting in a memory leak.

      Oh dear, the biggest fallacy about garbage collection rears its head once again.

      You can leak memory in GC'd systems. But unlike with deterministic memory allocation (like C/C++) determining where the memory leaks are is much harder. And typically the engineers using GC'd languages have fallen for the fallacy above and think their system can't leak memory at all. Which means they are not even aware of any potential problems let alone looking to identify and fix them.

      The few years I spent working in Java felt like working in a straight jacket compared to working in C++. Truly awful language.

    36. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      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.)

      I doubt that except in cases where the code has very short life span (i.e., weeks or possibly months). Automatic memory management is one reason why people raised on Java -- including myself -- write such poorly designed programs. When you're overworked and there's no obvious need to establish ownership of objects or arrays (with automatic memory management), that leads to a lot of making shit up as you're banging out lines of code. Yeah, the initial productivity was great, but the poor performance, bugs, and crap design hit you harder in the long run. Once I moved to manual memory management, there was no question that I had to establish clear ownership of arrays with every single malloc() no matter what kind of rush I was in -- and I've never regretted that.

    37. Re:C/C++ faster but produces more bugs by dkf · · Score: 1

      That's true of reference counting (shared_ptr), not unique_ptr/scoped_ptr, std::array, vector or similar which compile to equivalent C code.

      But then you've got objects of the lifespan implied by those entities. If you want to have objects that don't have a tight owning scope or container, then you've got to either put the free/delete in the right place (hard!) or use reference counting, or use garbage collection. You can wrap up lots of stuff around that, but ultimately that's the type of technique you need. That in turn means you've got to pay the cost of the technique. C++'s advantage is that it gives you the flexibility to use a variety of techniques as appropriate. C++'s disadvantage is that you have to select the right technique and it's not guaranteed to be nice if you get it wrong. (Code that runs in a managed environment is more expensive, but much less destructive when things go awry. It's a trade-off.)

      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
    38. Re:C/C++ faster but produces more bugs by EvanED · · Score: 1

      If you know and understand computers, c++ is fairly easy as it doesnt obfuscate things the way java does.

      Hmm, to be honest, there's one part of both of those languages that I don't have a good idea how to implement, and that's exceptions. (Hey, that's in both languages!)

      pros should know their c.

      They should. That doesn't mean they should use it.

    39. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      Bugs is produced by people, not languages.

    40. Re:C/C++ faster but produces more bugs by Erbo · · Score: 1
      Oh, granted, there's no substitute for good, careful design in any language. I just cleared up a problem in my company's massive Java application today which involved an extra object copy being created and then persisted to the database, resulting in a "concurrent modification" error message (as one copy in memory was no longer in sync with the one in the database). Sometimes it can be so easy and painless to create a new object, that you don't stop and ask whether you really should.

      But simply due to automatic memory management, there are whole classes of bugs, some of them nasty, in C++ that simply do not exist in Java. (And, of course, Java probably has a few that C++ doesn't have. Perfection is nonexistent. You pays your money and you takes your choice.)

      --
      Be who you are...and be it in style!
    41. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      for the programmer maybe, but not for the user.. make a program stack out of 'managed code' binaries and you'll see what I mean.. the performance aggregates.

    42. Re:C/C++ faster but produces more bugs by Kjella · · Score: 1

      Personally I've found that the easiest way is to use C++/Qt and not use new/delete on anything but QObjects, then value classes. For example my app has a FooManager that has a QHash<FooId,Foo> map. I just call FooManager->deleteLater(); and we're done. Or I have QObject children to the managing object. So I can have a connection manager, and the connections are all children of the manager so I can just call deleteLater() and the connections will go away too.

      Essentially I have a memory management tree, The fingertip is child of the finger is child of the hand (many to one) is child of the wrist is child of the underarm is child of the elbow is child of the overarm is child of the shoulder. Chop it off at the shoulder and it all goes away automatically, exactly once. Just remember to hook up everything up to the parent it belongs to in the constructor and don't pass your fingers to your feet, they can call but not take ownership.

      I also can't really lose memory. I can accidentally create children and lose all reference to it, but it's always there through QObject::children() so it's never truly lost. I can always map it all out in a debug function and see my "lost" objects. If there's some lost memory still then it's a Qt bug. The downside is that I am losing a bit of C++'s smart pointer passing, but through implicit sharing and copy-on-write it's not really making all those copies anyway.

      --
      Live today, because you never know what tomorrow brings
    43. 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"
    44. Re:C/C++ faster but produces more bugs by jabjoe · · Score: 1

      That's the old JIT argument, and while in theory it might have some merit, in the last decade it shown not to. Christ, a great deal of stuff still targets i386 just to ensure it runs on everything, and yet those apps still out perform Java/C# apps. Why? Because the core instructions are still the core instructions and the old RISC rule holds true, most of the work is done using a few key instructions. Plus where the JIT argument breaks down is with things like DLLs. The DLL can be very specific for the computer, and old applications link in that DLL to do the work, and thus the work in question for the old application is done with the latest, computer specific, stuff. If you want speed, use pre-canned stuff, if you want productivity use something like python, if you want both, probably best use a language for each. For instance core logic in C, and GUI stuff in python. Or use C++ and except the complexity that adds. If you want to have both but are willy to compromise to have both, then maybe that is where JIT languages come in.

    45. Re:C/C++ faster but produces more bugs by julesh · · Score: 1

      I am not OP anonymous coward, but for I can say this: Yes, sometimes I have memory problem in C++. Like 3 or 4 times a year. So the problem exists, but it is much much less serious than GC proponents attempt to claim.

      And how much time do you spend thinking about memory management issues in an average day? It's very hard to measure, but I'm willing to guess it's not trivial. Tracking down bugs is not the only cost associated with manual memory management.

    46. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      And, while C++ will always necessarily be faster to execute,

      Actually I don't agree with this. I can imagine situations where a compiler finds certain languages easier to optimise than others. C++ is probably the best in the general case, on average, however.

    47. Re:C/C++ faster but produces more bugs by MadKeithV · · Score: 1

      That's the old JIT argument, and while in theory it might have some merit, in the last decade it shown not to.

      Hence the "mostly academic" heading of my post. You agree with me that in theory a JIT compiler could be faster, thus C++ is not "necessarily" faster, but "practically" it is (when the code is well-written).

    48. Re:C/C++ faster but produces more bugs by TheRaven64 · · Score: 1

      Let me guess, you don't write libraries, and you don't write multithreaded code. When you're returning pointers to other people's code, and when you're having objects aliased across a few dozen threads and want to free them as soon as they are no longer accessed, memory management is a hard problem.

      --
      I am TheRaven on Soylent News
    49. Re:C/C++ faster but produces more bugs by w_dragon · · Score: 1

      Or you can do reference-counted pointers from boost or c++0x for almost free, a couple extra processor cycles when a local copy of the pointer is copied or deleted, and a risk of cycles stopping deletion. You can use the STL vector class rather than arrays and worry less about going off the end of the array (with the tradeoff being that you have to worry about the massive penalty if your array is resized, and iterator invalidation, etc). As someone who interviews for a primarily C++ position I can't describe enough how depressing it is how many people call themselves C/C++ developers (as if that means anything, very different languages) without having any idea how to use the STL, or what the power of templates can really do to make your codebase much smaller.

    50. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      You are right. Furthermore, they only compared C++ to four other languages, and took more care to optimise the C++ version, so it was an uneven comparison.
      Also, I have a tendency of reading the descriptions of the vulnerability description pages of all Windows updates I install, and I get the impression that the most common vulnerabilities are buffer overruns and their kin, and double-frees in IE. I have come to prefer safety to speed.
      And you also have to consider programmer time. C++ is a pain to code in compared to say Java or VB (and I originally come from the C++ corner), which makes C++ code more expensive. In business, that means a great deal.

    51. 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.
    52. Re:C/C++ faster but produces more bugs by syousef · · Score: 1

      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.

      Well then, don't be a one-trick pony. Learn another few languages.

      I use both Java and C in my current role, and move between code bases as needed. My C skills are more valued because they are becoming scarce and people are trying to avoid C work. If the C code dries up, I still have my Java experience (and have fiddled with several other languages). I speak from experience. My previous job was Smalltalk and Java. Believe me when I say Smalltalk jobs have pretty much dried up.

      --
      These posts express my own personal views, not those of my employer
    53. Re:C/C++ faster but produces more bugs by syousef · · Score: 1

      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.

      No, sir. Not Java. When you do Enterprise Java you learn a new flavour of the month framework every 18 months for each facet of your project (Struts to Spring MVC and Acegi to Spring Security totally reworked, every realse of Hibernate is different etc.) The code is never mature and the bugs really really suck. The language spec itself keeps changing and while the new features can be useful they are almost always misused. It becomes impossible to debug anything without spending days in the framework source. It's a fucking mess!!! The worst thing is it seems like nothing actually fucking improves. It's just rework and a new "best practice" methodology, religion and framework every year. Heaven forbid you don't comply! FUUUUCCCCKKKK!!!!!

      --
      These posts express my own personal views, not those of my employer
    54. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      That sort of attitude gets a bit expensive when an Ariane 5 rocket blows up because of some minor test code discrepancies. For debug mode sure, but sometimes in release mode you don't want the software to destroy property or kill people just because of some little bug, which may or may not be important.

    55. Re:C/C++ faster but produces more bugs by master_p · · Score: 1

      Wow. As if smart pointer classes never existed.

      Seriously, why are people still managing memory manually in c++? I haven't done so a few years now, using boost smart pointers, and now I am planning for using std::shared_ptr.

    56. Re:C/C++ faster but produces more bugs by GauteL · · Score: 0

      "What you are referring to is when you want the resource to be cleaned up."

      And you _very_ often want to clean up that resource straight away. Otherwise your applications resource use becomes incredibly unpredictable. This may be ok for memory (if you have enough of it), but it is NOT ok for things like file pointers and sockets.

      There is a reason why the IDisposable interface exists in C# and its use being so incredibly pervasive. And I have to say that I don't find IDisposable any easier than manual C++ resource management.

    57. 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.

    58. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      Agreed. Don't blame the tool, blame the carpenter.

    59. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      but when it comes to writing bug proof code, its not so good.

      [citation needed] - at this point, I'd think you're dealing with programmer experience, skill.

    60. Re:C/C++ faster but produces more bugs by Puff_Of_Hot_Air · · Score: 1

      Modern C++ is coded with smart pointers and the STL, which resolves both of the issues you mention. Yes there is a small performance penalty to pay, but profiling will reveal if these have any real impact. If so, the pointers can nude up to optimize the hot-path, something you just can't do outside of C++. To me, this is the power. I can be safe by default, and C or even asm, if I need to. Overkill on non performance critical projects, but the best tool for the job when it is. C++, the big ugly Swiss army knife.

    61. Re:C/C++ faster but produces more bugs by Almahtar · · Score: 1

      A good point. While it doesn't apply to every problem, scope-level memory management is much more reliable and high-performing than dynamic allocation. In some (very few: unbalanced binary trees, etc) situations it would be silly to use anything but dynamic allocation, but in most cases static is the best for performance and reliability by a long shot.

    62. Re:C/C++ faster but produces more bugs by StripedCow · · Score: 1

      Unfortunately, many programmers overlook the fact that, even in a completely memory managed environment, it is still very much possible to produce memory leaks. Maybe even more so because these programmers are not trained to think about memory management.

      For example, in any language with automatic garbage collection, allocate an array, fill it up with 100MB worth of data, and then store the reference to the array somewhere in a global object. If you forget about that reference, well, there you go: a memory leak!

      --
      If Pandora's box is destined to be opened, *I* want to be the one to open it.
    63. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      You may think of yourself as a "good" C programmer, but even "good" ones aren't that good. The reason we have phrases like "root kit" and "remote code execution vulnerability" in our vocabulary is because some of the best C programmers made mistakes that led to security holes. A simple off-by-1 error that immediately crashes a C# or Java program so you can debug it, in C or C++ will silently corrupt memory. This silent memory corruption might never cause a problem, might cause random crashes at arbitrary times in the future that are impossible to debug, or might allow remote code execution.

      dom

    64. Re:C/C++ faster but produces more bugs by m50d · · Score: 1

      Consequently used modern C++ doesn't behave any different from a GCd language.

      Except all your lines are two hundred characters long, full of std:: and angle brackets.

      Sure, it's possible to write code like you'd get in a modern GC'd language in C++. But why would you? It's not going to perform better (see the article, the performance was the same until they brought in a C++ expert to very carefully tune the C++ version), and it's going to be harder to write, and buggier.

      --
      I am trolling
    65. Re:C/C++ faster but produces more bugs by m50d · · Score: 1

      No, I'm good enough to realize that my time is better spent actually solving problems than doing manual memory management (which is and always will be tedious and error-prone). And unless you're claiming you've never introduced a memory leak or a race condition, then no, in C you will produce more bugs in the same program.

      --
      I am trolling
    66. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      > Three words: Automatic memory management.

      Another three words: Bull fucking shit.

      I have been working on a prototype of a medium-ish piece of software - in java. Uses Batik. The server (servlet-container) crashes every once in a while because, guess what, Batik leaks memory. Automatic memory management my ass.

      Also, if a non 100% memory management is what counts as the bees knees, google boost:shared_ptr.

      I use java when i need to - and i've written quite a bit of software in it over the years. But i'm sick of people spewing phrases that rightfully only belong on a marketing brochure. For a language that "doesn't have pointers" it sure has lots of NullPointerException.

    67. Re:C/C++ faster but produces more bugs by Paul+Dubuc · · Score: 1

      "It's not that I can't figure it out. It's that I don't *care*." You should care. I once took a course in JBoss administration that included a section on tuning garbage collection. It convinced me that GC is a bad idea. It may make it easier for programmers but it shifts the burden for efficient memory management into a domain where it doesn't belong. Effective memory management is very sensitive to the design of the application. Shifting it to a generalized facility that runs garbage collection based on the short, medium or long duration of objects is an administrative nightmare. Someone writes an app that goes against the rules configured into the GC and the performance of the whole server suffers. So now we have training classes for Java programmers on how the GC works so they can write more efficient applications. How is that different from teaching C++ programmers a few simple code design disciplines (encapsulation, proper use of smart pointers, etc.) to minimize memory management problems in their code?

    68. Re:C/C++ faster but produces more bugs by steelfood · · Score: 1

      Automatic memory management is great when you need to write something that'll run quickly and then die. It's not so good when you need to write software that needs to work with a varying, but potentially large amounts of data and continue to run.

      Besides which, it makes developers sloppy, leading to all sorts of performance problems. Automatic memory management doesn't mean the developer doesn't think about how to manage memory. It means the developer doesn't have to worry about memory leaks. However, software developed without memory management considerations will hog up all of the system's resources and eventually fail to run.

      --
      "If a nation expects to be ignorant and free in a state of civilization, it expects what never was and never will be."
    69. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      You don't understand. There are ways of using memory without using new/delete. You can allocate statically, on the stack and you can use containers to do the memory management for you.

    70. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      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.)

      Maybe, depending on which languages the programmer is comfortable in. It would be much faster for me to develop ${BLAH} in C++ than it would be in Go (because I don't know it).

      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 don't need to worry about any of this if you're using the STL's containers. Which you should be really, as they're excellent.

      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.

      How often do you return a pointer from a function in C++? It's not necessary in the majority of cases

    71. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      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.

      maybe. Instead of calling free down on the bottom of a delete it just marks it and it gets GC'd. In fact this option is going into the next version of C++ so be ready for it. Delete is just another method that you can override... People sometimes forget that.

      You can write just as memory happy code in C++ as you can in Java (having done it several times...). It costs you in performance though as instead of GC (which is just delayed deletion) it does it immediately. As when an object goes out of scope the object is deleted. You do a 'new' though and poof you are using global scope. Java/Python/C# and others try to 'figure it out' if you are still using it. Which leads to other bugs such as something really needed to be global scope and hang out forever but didnt.

      You can write crap code in any language. Anyone who thinks different is touting their fav lang of the day. Some languages have different gotchas than others. C++/C let you mess with memory pretty closely. You do not HAVE to do that. People do it though because it is easy. People also confuse easy with good. The CRT that most of these are based on do not help. As they encourage you to do bad things. The language itself is not 'bad/good'. It is the practices you use with it that make it good or bad.

    72. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      It's harder to be a good C programmer than to be a good Java programmer. Thus his point still stands.

    73. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      Are you qualified for this?
      http://hire.jobvite.com/Jobvite/Job.aspx?m=ndx6Sgwt&o=34&j=oWrjVfwl

      It does require C#, but you could put your C/C++ to use (presuming you have 5 years + of experience).

    74. Re:C/C++ faster but produces more bugs by Erbo · · Score: 1
      That should really have been called "NullReferenceException" but Java baked that mistake in pretty early on, so we're stuck with NPE.

      I've also opined that Java really needs to adopt the "safe navigation" operator from Groovy, which acts like the regular "." operator, but, if the left side is null, returns null rather than throwing NPE. In effect, the expression "a?.b" is equivalent to "a == null ? null : a.b". That alone would help eliminate a bunch of the NPEs I see on a regular basis.

      --
      Be who you are...and be it in style!
    75. Re:C/C++ faster but produces more bugs by cathector · · Score: 1

      i strenuously disagree that memory management is a boon to developer productivity.
      in every single case where i've seen serious memory requirements meet garbage collection,
      not only has performance suffered, but developers spend scads of time banging their heads against the black box of the GC.
      i'm thinking specifically AS3 and Java.

      imo GC is a lose-lose proposition:
      either 1) you have serious memory requirements, in which case GC just gets in your way and you have to expend serious effort Working Around it,
      or 2) you don't have serious memory requirements, in which case who gives a shit: leak the stuff. virtual memory is essentially infinite.
      the only situation where the GC really helps are in long-running but memory-unintensive applications.

    76. Re:C/C++ faster but produces more bugs by snadrus · · Score: 1

      I fix for C++ & Java bugs. Error rates are the same afact, but C++ code is full of reimplemented mem tracing and (for C adapted code) error handling code making the functionality obscured. Features are assets, but code is liability. So any feature gained with cleaner code is better.
      So I write tools in Python for a minimum of code with high readability.

      --
      Science & open-source build trust from peer review. Learn systems you can trust.
    77. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      Do you really think reference counting is much of a burden, though? More so than GC?

      I mean... With reference counting you have increased indirection over say a stack-based variable, because everything must live on the heap. You have to increment or decrement a counter every so often. That should be pretty cheap. In a multi-threaded environment that has to be done with atomic ops, which is probably the most costly thing in the whole equation.

      Now, GC... Still everything is on the heap, so you have that increased indirection over stack-based stuff. Then you have to periodically scan a potentially large number of objects to see what's orphaned and reclaimable. I guess a generational collector can help keep that set small, but... that sounds a lot scarier to me than maintaining a count.

    78. Re:C/C++ faster but produces more bugs by BravoZuluM · · Score: 1

      I'm not posting as an anonymous coward.

        I've been coding for 25 years. I rarely have memory leaks, and I NEVER have double frees. IF I have a memory leak, it is because I am doing something novel and specialized. That leak is caught before the app goes out the door. These applications that I've developed are among a number of commercial titles that shipped to retail stores. I use patterns for memory management and memory ownership. I also make use of well tested frameworks. I don't use Boost but have opted for QT instead. It works for me.

      I can't speak for the Coverity open source scan effort but I know a number of developers who would make the same statement that I am making. Most of the developers I know don't do it for the passion of programming. They do it because they can make a lot of money coding for others. Their code....usually sucks. I find that most developers excel at being clever and I've seen some pretty wacky coding practices on the C++ side of things. But just because that exists, doesn't mean there are C++ developers who truly excel at coding C++.

      I once wrote a commercial, a specialized app, but there were 10s of thousands of users that only had one reported bug. That bug occured when there were no printers attached to the machine. It never occurred to me to test that use case. I wrote a server app that ran for 2 1/2 years before they took it down and restarted it. They were moving the servers to a different location. That app followed the producer/consumer pattern and is obviously multi-threaded. It used TCP/IP to retrieve data from a server and then populated a database with that data. If the data queue leaked memory, it wouldn't have run for 2 1/2 years.

      Posting on Slashdot against another developer and imposing your "facts" on him...is pretty brazen. Oh wait, this is Slashdot.

    79. Re:C/C++ faster but produces more bugs by Jonner · · Score: 1

      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.

      There are always trade-offs between development time, execution efficiency, robustness, and other properties. Why didn't they include x86 assembly language in their comparisons, though it could certainly be used to write more efficient machine code than C++? There was a time when anything other than C or C++ was seen as luxury programmers couldn't afford. Now, higher level, easier to use languages are generally acceptable for the vast majority of tasks. C and C++ should be reserved for the few cases when optimizations are needed that can't be achieved in a higher level language.

    80. Re:C/C++ faster but produces more bugs by msclrhd · · Score: 1

      You need to understand when resources are being cleaned up. Consider:

      public class Settings
      {
            public void Save()
            {
                  File f = new File("settings.txt"); // ...
            }

            public void SetFoo(int foo)
            {
                  m_foo = foo;
                  Save();
            }

            public void SetBar(int bar)
            {
                  m_bar = bar;
                  Save();
            }
      }

      Settings s = new Settings();
      s.SetFoo(1);
      s.SetBar(2);

      The SetBar call will fail as the garbage collector is still holding the file. Another case is a File->Save handler saving to the same file. The operation may fail the second time the user saves the file depending on whether the garbage collector has run.

      Or how about sockets in a web server application. Your program will fail very quickly if you don't release the sockets.

      Or how about database locks? Do you want random database failures?

    81. Re:C/C++ faster but produces more bugs by fyngyrz · · Score: 1


      You may think of yourself as a "good" C programmer, but even "good" ones aren't that good.

      Cite? Data? LOL.

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

      Heh, if people really were only concerned about programmer time, we'd all be coding in Lisp. However, we live in the real world. Plus, on an ethical level, if your program is to have a very large number of running copies, any inefficiency translates into more energy used than had a programmer spent more time using C++ and optimizing.

      --
      "Politicians and diapers must be changed often, and for the same reason."
    83. Re:C/C++ faster but produces more bugs by Deorus · · Score: 1

      &gt: 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.

      If you do understand the concepts and implementations of smart pointers and containers in C++ then why the hell are you still talking about C++ as if it did not support automatic memory management?

    84. Re:C/C++ faster but produces more bugs by Deorus · · Score: 1

      You can implement smart pointers and containers in C++, if manual memory management is such a pain for you. That is, in fact, the beauty of the language; you have a lot of paradigms at your disposal but the language doesn't get in the way if you choose not to use them.

    85. Re:C/C++ faster but produces more bugs by fyngyrz · · Score: 1

      See, what you've just admitted is simply that you failed to even try to solve the problem. Like most things in programming, it's amenable to effort, and there are significant rewards.

      First thing I do on a new project is incorporate my development memory code; I get pools, cached pre-allocators, null pointer checking prior to every use, prior to deallocation, and on allocation; memory consumption tracking both in amount and allocate/deallocate counters, reference counting, over- and under-run barriers, named, unfreed capture and unfreed re-allocation trapping, barriered arrays and exposed (defeatable) array accessors, and a good deal more. This adds about 50k to the target executable during development.

      Then, when it's release time, I simply switch to the release version, which recompiles into lean, mean memory handling, about 3k, knowing that any problems -- which, frankly, after decades of doing this, are few -- have already been caught. Exposed accessors and so forth are still there, no overruns happening, etc. So I don't spend time "doing memory management"; No null pointers, no buffer overruns, no issues at all, and no particular work to make it all happen. Code once, enjoy the many, many benefits thereafter. Completely under control. And that goes for a lot of other things you might consider "c issues", too -- over the years, you (well, I) learn to solve problems in a way that moves forward with you. These are *tiny* chunks of code, not these massive frameworks from Waste-O-Rama, Inc.

      In the end, I produce a faster, leaner, more efficient app that saves the user time with every action; is much easier to maintain (either fix or upgrade) because it doesn't depend on external libraries and frameworks I don't have control over; saves download time simply because it's much smaller than a comparable C++ etc. application; doesn't unethically trade the user's application space for any perceived development effort savings, and is known to have a very high degree of correctness on its way out the door. If someone finds a problem, I can fix it in minutes, because there are no black boxes. Users like that, too... email in, fix comes back in half an hour. Kind of sets them on their heels, for some reason... guess they're used to something else, eh?

      I even get to use all manner of OO techniques - objects with built in functions, allocators, class functions, object functions, etc., but the difference is, I have complete control over them; I'm not at the mercy of the compiler, framework, or otherwise private libraries, because they're built using my own code and methods. I'm not tied to any particular GUI generator (that's a real issue in Apple's OSX), and I don't have to worry about dragging little lines around to connect my objects -- that's all done "in your face", in code -- no hidden black box nonsense. My buddy back on the east coast spent many hours last week trying to incorporate Apple's treeview control... I have a pile of email from him complaining about the built-in bugs... I just LOL'd and showed him my treeview library. Bugfree and more functional than Apple's, anyway. Nothing beats having your own code. Other People's Code is almost always an invitation to trouble, and that is especially true if it is some major company's, because they simply are not going to be responsive to your needs.

      And as to race conditions... I write real time, multi-threaded signal processing code. I invented some of the current AFSK modes. My latest project is a multicore aware, user-core-utilization selectable image processing suite -- in beta now (see it on the middle two monitors?) -- that makes Aperture look like a box of slow, clumsy crayons, but is a fraction of its size and offers *far* more in terms of functionality, even incorporates an astrophoto processing system. About 99% c, the rest is an obj-c application wrapper. I think I might know a little bit about how not to trample my own toes in this regard.

      No

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

      No. It's not harder. It's just different. Java poses some huge challenges at times; to be "good", you should be able to say you can meet them. c challenges are very different, and frankly, they're simpler, but again, to be good, you still have to meet them. There are some traps -- the "standard" (K&R and derived) code formatting puts an instant hurt on comprehension, and a lot of programmers have fallen for that because no one has taken the time to show them there is a better way -- many of them are now habituated and can't get beyond it.

      The only languages I've ever run into that were legitimately "harder" brought a different type of challenge to the table: APL, for instance, is actually a harder language because you have a lot of non-intuitive learning to do, and you need to make it intuitive if you're going to be any good. It's like learning Klingon.

      Some languages form a natural progression of learning: asm to forth to c is a very natural progression, for instance, even though one is direct, one can be interpreted, compiled or byte-coded and is RPN-ish to boot, and the last is almost always primarily algebraic and compiled. So it's an easy learning curve. There's nothing easy about APL, it'll make your brain bleed. Lisp is no picnic, either; visually speaking, it's a bitch, and that makes it difficult to learn. Python is so easy to learn -- and powerful -- it's almost ridiculous. Perl is powerful, but hugely annoying in its non-intuitive symbol-soupness and the first time you try to deal with Other People's Code in perl, you'll learn why the best programmers moved right over to Python as soon as they understood what it offered.

      Anyway, no, Java and c... not really different in terms of getting good. Perhaps what has really caught your attention is that there aren't that many good programmers, period. That's where languages with training wheels - memory, lists, dictionaries, the lovely exception handling exemplified in python -- help them along far enough so they can make production code anyway. The resulting apps are inevitably slower, larger, and more fragile than what a good programmer would have made, but you know, they mostly do the job, and that's what the poor public has become accustomed to.

      I start the "Island HD" game on my ipad, it cranks for a minute, then crashes. Yep, pretty much par for the course. I start it again, this time it runs. Looks like the OS had a little more memory in a single chunk that time... I start the NPR news app, it can't get to the server, it crashes in the middle of loading a news item. Same thing for my Pulse news reader. Can't get to an article... crash. Chess with Friends: start it, it's a toss up if it'll crash or not. Once running, it appears stable, though. On the Mac, every time a cron job starts, OSX pukes an (incorrect) error message to the console. I use cron a lot, so that got really old... and so I fixed it. And then we get into issues where some fool thinks its ok to constantly prod you to "connect to facebook" and leaves you no way to say, "I'm not on idiot facebook, nor will I ever be, so stop doing that." Just lousy programmers everywhere.

      Yeah, that's the main problem. Not c or java.

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

      Python 2.x comprises an awesome language series. A real shame about python 3's incompatabilities, but we still have python 2.x, so it's far from a total loss. And perhaps ol' Guido will wise up and turn back to maintaining a properly compatible upward development course with the 2.x series. One can hope.

      Huge fan of Python, myself. This is my python code for instance... it's an aurora detection and prediction system that sends me an SMS whenever I need to get out there with my camera. And as you can see, it works for me. Uses PyEphem and PIL, otherwise comprised of my code, my meter and web scraping libraries, etc.

      --
      I've fallen off your lawn, and I can't get up.
    88. Re:C/C++ faster but produces more bugs by m50d · · Score: 1
      I've written C where I needed to, and of course I wrote bits and pieces around its problems - though these (quite rightly) belong to what are now previous employers. But in most cases it's just a load of time and effort overhead for little benefit. Your libraries may let you find memory management problems quicker, but they don't save you having to think about the memory management, wasting brainspace that would be better used on the problem the application's trying to solve. (Either that or they abstract it away enough that you no longer have hand control - at which point, you've just come a long way around to where those of us in better languages already are). As for maintenance, I can make, test and release a bugfix in less time than it takes a decent-sized C program to compile.

      When we come to libraries, you seem to be taking the position that your code will always be better than other people's. Maybe that's the case for you, but it trivially isn't for the vast majority of programmers. For any normal programmer, reimplementing functionality found in an existing library is just a waste of their time - custom code is more likely to be buggy than a widely used library (because the average programmer won't be better than the library's authors, and there will have been more opportunity to find bugs in the library). I fear you're wasting your talents doing things that have already been done, and making your applications use less memory rather than making them do more.

      --
      I am trolling
    89. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      [quote]
      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.
      [/quote]

      I'd argue (strongly) the other way: good C/C++ skills are more likely to land a _well_ paying job. Want to do embedded work, your realistic choices are: C, C++ or use JaveME and watch you application run like molasses. Additionally, it is much easier for a good C++ programmer to be a good Java or C# programmer than the other way around. I have seen way too many Java monkeys not able to cope with understanding the underlying bits of a computer.

      Lastly, though GC is one of the big points of Java and C#, there are other cleanup issues beyond freeing memory, both of these languages are problematic at times (can we say RAII?) The argument for GC is, in my opinion, that too many people are too careless when they code. Memory leaks are avoided with a touch of discipline and awareness, needed anyways to get anything off the ground. The GC is a major hassle in Java to get any hope of performance for Java (and C#) performance. Nobody makes systems with real time performance requirements in Java or C# as all of the current implementations found for both, their GC does not let one be able to guarantee any real time performance. The other ugly of GC is communicating data to bits not coded in the same language, marshalling sucks, pinning the data is a hack-ish thing. Where as in C and C++, it is just bytes and the developer controls the situation, so it is so much easier to call functions to outside the language.

      The crap about writing past array sizes and such is epic bullshit in C++, most STL implementation have an option to enable bounds checking (i.e. assert) for STL vectors, so past the end of the array is mostly avoidable (and in addition many STL implementation implement extra debug checks for iterators too!) My main hate for C++ code is syntax errors from heavy template code, that bytes.

      I'd use Java or C# for something that performance is not an issue and if it runs on a desktop.. but embedded, shudders.

      My 2 cents.

    90. Re:C/C++ faster but produces more bugs by Erbo · · Score: 1
      Granted. The most extreme example of this is embedded development, which is one of those "corner cases" I referred to where C++ is justifiable and languages such as Java are definitely contraindicated.

      Of course, never forget the Laws of Code Optimization:

      • The First Law of Code Optimization: Don't do it.
      • The Second Law of Code Optimization (advanced experts only!): Don't do it yet.
      --
      Be who you are...and be it in style!
    91. Re:C/C++ faster but produces more bugs by shutdown+-p+now · · Score: 1

      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.

      I won't dispute this since I never tried to find a job purely as a C++ programmer, but what I do know is that there is significant demand for .NET programmers who also know C++ well. The kind of folk who can optimize C# programs by rewriting parts of them in C++ (with a good understanding of how interop between two parts will work & how to make it efficient), or who can maintain that legacy C++ COM component used by a .NET app.

      I wouldn't be surprised if there was a similar demand for Java programmers with good C/C++ knowledge, to work with JNI and such.

    92. Re:C/C++ faster but produces more bugs by ceoyoyo · · Score: 1

      It's weird how scared the Java kids are of things like memory allocation and pointers. I wonder what they'd do if they saw a jmp?

    93. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      You can leak memory in GC'd systems. But unlike with deterministic memory allocation (like C/C++) determining where the memory leaks are is much harder. And typically the engineers using GC'd languages have fallen for the fallacy above and think their system can't leak memory at all. Which means they are not even aware of any potential problems let alone looking to identify and fix them.

      The few years I spent working in Java felt like working in a straight jacket compared to working in C++. Truly awful language.

      I can run jmap -histo on any running application without starting it in a debug mode or whatever. Other GC'd systems could potentially do the same. With C/C++ you'd have to start the program in some kind of memory profiling tool, and instead of object counts, you'll have malloc counts. Either way, the hard part is after all that.

      There is nothing deterministic about when something _should have_ been freed.

    94. Re:C/C++ faster but produces more bugs by fyngyrz · · Score: 1


      Your libraries may let you find memory management problems quicker, but they don't save you having to think about the memory management, wasting brainspace that would be better used on the problem the application's trying to solve. (Either that or they abstract it away enough that you no longer have hand control - at which point, you've just come a long way around to where those of us in better languages already are)

      No, you don't understand at all. My libs let me write to a model that doesn't carry the release-level baggage that your "better languages" do; consequently my release code is both faster and lighter than that produced with, for instance, objc or c++, etc. But during development, I receive all manner of feedback if anything goes wrong, which bulletproofs the things I'm doing BEFORE they are let loose without protection, lightweight and fast. Your "better language" is always dragging around heavy and clumsy memory managers that are generalized and not optimal; my memory code is much better because it's always case-specific. And it doesn't waste the user's resources. And there's never any GC stumbling about, either.


      When we come to libraries, you seem to be taking the position that your code will always be better than other people's.

      No. I'm taking the position that my code is more maintainable by me than other people's, and the only reasons I say that are because (a) I have the source and (b) I wrote the source, so I understand it intimately. For any framework where I don't have the source, fixing a problem *is* a problem. Trying to get Apple to fix a framework bug is like trying to push a Sherman tank uphill with a wet noodle. If I do have the source, for instance, lets say the JPEG libs, there can be massive slogging around trying to figure out why, for instance, setting the chroma resolution to 1x1 instead of 2x2 doesn't work in the new lib, but did in the old lib. Whereas if I use my jpeg library, not only do I have control over this (and it continues to work), but I can also load all those jpeg variants that won't load with the standard IJPG libs and I can let a configurable number of cores loose on different compression blocks, which gives me a huge speed advantage over, say, the IJPG libs. Likewise, if I use my treeview, the treeview works properly. If I use theirs... well, just Google it, you'll see the problems, which are many. Their treeview is a nightmare collection of screwups. And so on.


      I fear you're wasting your talents

      No, I'm not. Believe it.

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

      ... sometimes in release mode you don't want the software to destroy property or kill people just because of some little bug, which may or may not be important.

      Sure, real-time control systems need to provide reasonable output regardless of any inputs. However, for most other systems I've found that "get out of dodge" is still the best answer. The top-level program can simply be run in a loop that says "re-execute program with an incrementing counter if it ever exits due to SIGABRT".

    96. Re:C/C++ faster but produces more bugs by Anonymous Coward · · Score: 0

      Well, the whole point of C++ is that it's compatible with C. And for that design decision, it paid dearly. You have all the methods of shooting yourself in the foot with C magnified by the higher-level programming features of C++. I won't go so far as to say it's impossible to write bug-free C++ code, but I will say it's far more difficult than almost any other modern language (if one could call C++ a modern language).

    97. Re:C/C++ faster but produces more bugs by maxwell+demon · · Score: 1

      but there's no program path which will ever access it again, and thus it should be discarded

      Memory management does not work that way (also lol halting problem).

      First: That was a definition of "memory leak" which is completely independent of any way memory works or doesn't work. Ans as such, the halting problem is irrelevant for it (it does imply that for this definition of "memory leak" it is impossible to write an algorithm which in finite time tells for an arbitrary program whether it will be leak-free for any input, but that's true also for the more conservative definition, so it's irrelevant).

      But the halting problem is irrelevant here also in another way: It says that you cannot write an algorithm which decides for an arbitrary program whether it halts. That doesn't imply that it isn't possible for a certain given program to tell whether it halts (indeed, it's trivial to decide that int main(){} always halts, int main() { while(1); } never does). And it especially doesn't tell you about the properties of well written programs.

      Wielding the halting problem doesn't get you anywhere, unless you are speaking about mandatory behaviour of compilers.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    98. Re:C/C++ faster but produces more bugs by SomeStupidNickName12 · · Score: 1

      Your architect is an idiot, stop changing your framework every time you have you have a new facet to the project.

      We picked Jboss seam 3 years ago for the new major version of our core solution and we haven't changed since. Yeah other frameworks do certain things better/worse but changing isn't worth the headache.

    99. Re:C/C++ faster but produces more bugs by SomeStupidNickName12 · · Score: 1

      Huh?? Have you seen some of the enterprise level java solutions? I get better reliability out of JBoss(Java Based) than I do off the C++ database(MySQL) it connects to

      Poor performance caused by a lazy developer is just that poor performance caused by a lazy developer, automatic memory management is just tool that can be used or misused. In a c++ world the lazy developer would have code with memory leaks and buffer problems

  6. Garbage collection by MrEricSir · · Score: 1

    FTA: "All languages but C++ are garbage collected, where Scala and Java share the same garbage collector."

    That's got to play a factor here.

    --
    There's no -1 for "I don't get it."
    1. Re:Garbage collection by Toksyuryel · · Score: 1

      Because clearly C is garbage collected. It all makes sense now.

    2. Re:Garbage collection by MrEricSir · · Score: 1

      Because clearly you need to re-read this thread. It will all make sense then.

      --
      There's no -1 for "I don't get it."
    3. Re:Garbage collection by Anonymous Coward · · Score: 0

      C isn't even a factor in the type of development they do. Why compare to a language that's only relevant in a few specific fields?

      C++ hardly fits Google as it is. Their style guide is an unholy abomination (albeit probably a necessary one for a corp of that size). Not surprising that they're looking into more modern languages.

    4. Re:Garbage collection by jd · · Score: 1

      I'm sure there's a malloc replacement library out there that does GC. :)

      --
      It's a small world and it smells funny; I'd buy another if it wasn't for the money; Take back what I paid (SoM)
    5. Re:Garbage collection by TheRaven64 · · Score: 1

      Yes, there's libgc. It turns malloc() into a GC-backed alloc (optionally from a per-thread allocator) and free() into a no-op. It periodically scans all mapped memory (incrementally, via some tricks) to find unreferenced allocations and frees them. In most cases, the performance is within about 10% of manual memory management, and that's the absolute worst case for it.

      That's the worst possible way of using it though. You can get significant performance improvements by explicitly marking pointer locations in structures. I used it to implement Apple-compatible GC in the GNUstep Objective-C runtime, and some tests showed that the GC was only looking at about 5-10% of the total memory allocation. The other 90-95% was guaranteed not to contain pointers to GC'd memory (e.g. frame buffers, images, large strings, and so on). That's actually quite conservative, because a lot of the code wasn't written with GC in mind - with some tuning for GC I wouldn't be surprised if it got well under 5%.

      --
      I am TheRaven on Soylent News
    6. Re:Garbage collection by Anonymous Coward · · Score: 0

      bah, it's a little silly to claim one of those other languages might outperform C++ or C, since every possible feature in those languages can be replicated in C or C++. In fact, since the compiler/vm/etc were probably written in C++ the performance of any of those tools IS C++ performance.

  7. 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"?
    1. Re:Language shoot-out confirmed by Anonymous Coward · · Score: 0

      The computer language shootout is actively eliminating (as in removing the benchmarks) anything that starts to compete with his own favourite languages. For example you may think that javascript is the fastest dynamic language, but it is only the fastest of those that are allowed to use JIT. Python and Lua are not allowed, so take it with a grain of salt

    2. Re:Language shoot-out confirmed by Anonymous Coward · · Score: 0

      The shoot-out says C is the fastest language, you point us to the best language page.

    3. Re:Language shoot-out confirmed by Just+Some+Guy · · Score: 1

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

      The one that ignores faster implementations of languages, just... because?

      --
      Dewey, what part of this looks like authorities should be involved?
  8. basic by theheadlessrabbit · · Score: 4, Funny

    They didn't test BASIC? Lame...

    --
    -I only code in BASIC.-
    1. Re:basic by ImprovOmega · · Score: 1

      The tests are still running. Results are expected next year some time.

    2. Re:basic by Anonymous Coward · · Score: 0

      The source code, in theory, shouldn't determine the execution speed of the resultant machine code. C# is not considered to be a performance slouch and VB.NET compiles down to the same CLR code and executed by the same engine so it's a bit unfair to just lump "Basic" into a single pile.

      As long as the language implementation/compiler is not un-optimized, everything should be nearly equally fast as the higher level languages are simply ways to abstract and centralize common functions in the lower-level languages.

    3. Re:basic by Anonymous Coward · · Score: 0

      You may cry but on a past life my boss asked to branch the company wide system, based on c++, gui client... to vb6 com dlls and custom scripted build, that linked vb6 generated obj files (one by every form or class) with selected few vc 2003 defined obj files to get one single com dll (to be loaded from a generic active document viewer exe)... the resulting system was smaller, faster, easier to evolve that the c++ one. And to this day its used and evolving (so far three skunk works projects to rewrite portions on net, have been canned after failing to give similar ease and efficience than the vb6/vc linked mutant)

  9. 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
  10. Google = Captain Obvious by DMFNR · · Score: 0

    What was even the point of comparing these 4 vastly different languages? Java and Scala both run in virtual machines so it's obvious a native compiled language is going to beat them out. C++ is a very mature and popular language with a heritage going back to an even more mature language, so obviously it'll beat out just about anything. I think the Go language is pointless to being with, but this would have been much more interesting if they did some benchmarks comparing it to some other compiled languages like Pascal, BASIC, FORTRAN, C/C++, or D just to see where it stands in the group. This just reeks of someone coming up with some busy work to make it look like they have something to do at Google.

    1. 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
    2. 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.
    3. Re:Google = Captain Obvious by steveha · · Score: 1

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

      Google has an official list of four languages that they approve for use: Java, JavaScript, C++, and Python.

      Most of their business runs on Java. Search, Google Maps, etc.

      YouTube mostly runs on Python, IIRC.

      So, they compared C++, on their list; Java, on their list; Scala, which is not on their list but runs on the JVM and thus would work for them; and a language invented at Google. They didn't test Python, but if they had it would have come in last place (and I say that as one who loves Python; it's reality).

      Why is it surprising that Google was testing languages that Google might use for projects?

      P.S. Exciting things are happening in the Python world with the PyPy project. PyPy is a Python system that is written in Python. You might expect that to be slow, and for years it was slow; but it includes a Just-in-Time compiler that generates native machine code, and it isn't slow anymore. In fact, it is now faster than the C Python, because it can optimize away lots of stuff that C Python has to do.

      http://pypy.org/

      steveha

      --
      lf(1): it's like ls(1) but sorts filenames by extension, tersely
    4. Re:Google = Captain Obvious by gonz · · Score: 1

      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.

      Here's some strong evidence to the contrary:

      http://reverseblade.blogspot.com/2009/02/c-versus-c-versus-java-performance.html

    5. Re:Google = Captain Obvious by maxwell+demon · · Score: 1

      In the absence of evidence to the contrary

      Which is exactly the point. You compare performance exactly in order to create evidence one way or the other.

      --
      The Tao of math: The numbers you can count are not the real numbers.
    6. Re:Google = Captain Obvious by jcupitt65 · · Score: 1

      Java and c# are rather close on that list, arent they? And both are slower than C++, sometimes significantly, on all but one test.

      Plus those tests are mostly very small numerical benchmarks which will not stress the GC much and which are not very representative of typical applications. As the google paper showed, gc tuning is an important part of application performance for larger projects.

    7. Re:Google = Captain Obvious by SpryGuy · · Score: 1

      It's surprising to me because it's so insular and doesn't really "prove" anything. It doesn't say "Hey, here's why we use Java and reject C#" or anything else that's in any way useful, that I can see.

      Again, I just don't see the point of this. I suppose it might have some meaning inside Google, but then why report on it like a story to anyone outside Google?

      --

      - Spryguy
      There are three kinds of people in this world: those that can count and those that can't
  11. So get more power by Anonymous Coward · · Score: 1

    A slower language just means you need to buy more rack space. A more expensive development language (like C++, which needs more skilled coders, more debug time, etc.), means that you need to buy more developer man-hours. As far as the business world is concerned, I thought everyone had come the conclusion already that as far as business apps go, C++ isn't generally worth it.

    Leave C++ for the games, the operating systems, and the frameworks that the higher level languages run on. But since everyone already knows this, TFA is kind of pointless.

    1. Re:So get more power by inglorion_on_the_net · · Score: 1

      A slower language just means you need to buy more rack space. A more expensive development language (like C++, which needs more skilled coders, more debug time, etc.), means that you need to buy more developer man-hours.

      Actually, either of those may be your best option, depending on the parameters.

      If a few hundred or thousand dollars gets you hardware that makes your software fast enough, that's probably cheaper than developing for optimal performance.

      If you operate at the scale Google does, the extra expense of letting developers squeeze as much performance as possible from the hardware may well be worth it - imagine cutting your hardware requirements, and the size of the army required to maintain all that hardware, in half.

      In some cases, optimizing for run-time performance is your only option, because throwing extra hardware at the problem simply won't get you there. I've been in this position before. This is also where I learned that, while picking a better language implementation certainly helps, doing your requirements analysis and architecture right can improve things by multiple orders of magnitude, or take you from impossible to possible.

      Finally, you need to consider the impact the run-time has on the users, and who the users are. If you are one of the users, you may well benefit from faster software, even if it costs more to develop.

      You are right that, in many cases, run-time performance of the software isn't very important - but those are not the interesting cases. The reason you would measure performance across languages at all is that you care about the cases where this performance matters.

      --
      Please correct me if I got my facts wrong.
    2. Re:So get more power by Ant+P. · · Score: 1

      A slower language just means you need to buy more rack space.

      And more racks. And a bigger datacentre. And more cooling. And more wattage. And bigger UPSes.

      But you're right, for software that isn't intended to last more than 3-4 years, something slow and shiny like Ruby is generally more cost-effective.

  12. Stupid sensational headline by Anonymous Coward · · Score: 0

    They only benchmarked 4 languages.

  13. write by Anonymous Coward · · Score: 0

    people should write dissertation on this..

  14. 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.
    2. Re:Environment, conditions and parameters by Vintermann · · Score: 1

      > I would be quite surprised if any C++ can execute a FFT as fast as my Leahy FORTRAN95.

      Have you looked at the Fastest Fourier Transform in the West (FFTW)? It's written in C - but the funny thing is, it's written in C by an OCaml program.

      I think this is the way forward for truly performance intensive code. Not doing it in C++, but writing dedicated compilers for specific subroutines, churning out C, assembly, or compiler specific intermediate language code. Functional languages should excel at this, they have been ruling the program transformation/analysis space for a long time.

      --
      xkcd is not in the sudoers file. This incident will be reported.
    3. Re:Environment, conditions and parameters by Anonymous Coward · · Score: 0

      Interesting. Was that Before Guild or After Guild?

    4. Re:Environment, conditions and parameters by MemoryDragon · · Score: 1

      It was not only blazingly fast (still is Delphi still exists) it also had a blazingly fast compiler. I can remember the switch from Borland Pascal to C++. I suddenly went from 1-2 second compiles per project to 10 minutes and more.

    5. Re:Environment, conditions and parameters by Anonymous Coward · · Score: 0

      Nothing about Lisp guarantees no side effects.

      Why do people keep parroting "Lisp is a functional language" when it isn't? It's as much a "functional language" as C and C++ are -- it all depends on how YOU, the PROGRAMMER, structures his program, whether you write in a functional style or not.

    6. Re:Environment, conditions and parameters by gay358 · · Score: 1

      Turbo/Borland Pascal compiler was extremely fast even by modern standards even though the machines were quite slow. However, the compiled code didn't ran as fast as C(++) code which was compiled with optimizing compilers.

      I remember that even on a slow XT computer, relative short programs often compiled so fast, that the compiling dialog disappeared before you could even notice it. I once thought that the keyboard shortcut for compiling was not working, because the dialog appeared and disappeared faster than I could see.

      It is sad to see that even on modern computers most compilers are nowhere near those speeds. Developing using Borland Pascal was really nice, because you didn't have to wait for long compiling process.

      I think there was several reasons for the extreme speed. Pascal was very easy language to parse compared to C++ and I think that some parts of the compiler were optimized using assembly. Borland Pascal syntax also made it possible to precompile separate units of code (unlike C(++) where you typically use header/include files with deep nesting that are usually parsed again and again) of code. And it also helped that the compiler didn't spend time optimizing the code.

    7. Re:Environment, conditions and parameters by backwardMechanic · · Score: 1

      So in some 18,000 years there will be a bunch of techs wondering why their galaxy-spanning computers are running a bit slow? Man, who expected hackers from the past?

    8. Re:Environment, conditions and parameters by Anonymous Coward · · Score: 0

      Delphi and FPC (free pascal) are still really fast. Pascal/object pascal routinely place near the top if not winning the odd code speed challenges. Granted, that's in part because the pascal guys are 'enthusiasts' with something to prove. In my experience, typical pascal code is really close to similar typical c code, just a hair slower. Verboseness or terseness is a matter of preference. Pascal is still a great choice for high performance applications if the verboseness isn't a stumbling block.

    9. Re:Environment, conditions and parameters by DMFNR · · Score: 0

      Pascal compilers usually use recursive decent parsers which are known for being pretty damn fast when implemented properly. The language as a whole was designed by Wirth to be compiled quickly. I think maybe the difference in speed between Borland Pascal and early C++ compilers is just the age of the languages in general. Pascal is an old ass language, right up there with FORTRAN and both of those call C "little bro". C++ was relativly new at the time, hell, object oriented languages were still young, so I'm sure Pascal was easier to generate code for because it's a less complex language and we've been doing it for so damn long at the time all the kinks were pretty much worked out.

    10. Re:Environment, conditions and parameters by gay358 · · Score: 1

      It is worth noting that also C compilers (not just C++ compilers) tend to be slow compared to Turbo/Borland Pascal even though as languages C and Pascal have about as long history and C compilers have received a lot more attention in compiler development. And Borland Pascal was/is also object oriented language, although not as complex as C++ was during that time (nowadays C++ is even more complex with templates, RTTI, exceptions etc).

      I have to wonder why language/compiler developers don't spend anymore so much attention to fast compiling. It is ridiculous that we have spend much more time for compiling than we had to 20 years ago, even though the computers are much faster. Slow compiling (and/or deploying speed) makes developing software unnecessarily slow and tedious process.

    11. Re:Environment, conditions and parameters by Jonner · · Score: 1

      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.

      Google's comparison didn't include those languages, but The Computer Language Benchmarks Game does. SBCL and GHC are near the top in performance, so you wouldn't have to sacrifice much to use them.

    12. Re:Environment, conditions and parameters by Prune · · Score: 1

      Fortran was matched by C++ shortly after template metaprogramming was discovered. You get the niceties of operator overloading and such without the previously implied performance overhead.

      --
      "Politicians and diapers must be changed often, and for the same reason."
    13. Re:Environment, conditions and parameters by Anonymous Coward · · Score: 0

      That... or was the time borland c suck big time, and crappy old ms visual c was better (vc 2003 was a big jump on quality)

  15. 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
    3. Re:Assembly by Anonymous Coward · · Score: 0

      I don't think you've proven anything except that you personally can't write masterful assembly.

    4. Re:Assembly by oiron · · Score: 1

      Reasonable c/c++ code can be as good as (or even better than) hand-tuned assembler. There's just no benefit to writing in ASM for most things.

      Basically, c/c++ code should nearly transform back into the equivalent assembler-generated code for almost anything, as long as your compiler is good.

    5. Re:Assembly by MacTO · · Score: 1

      Then you're doing assembly all wrong. Assembly language is quite easy to write in if you structure it properly.

      That said, it is an absolute bitch to read, which is why I prefer to deal with higher level languages any day. (Think about it: do you spend more time writing original code, or revising and debugging existing code? Even for a hobbiest such as myself, revising and debugging is a big part of what I do. I would imagine that the professionals spend much more time doing so since they're responsible for maintaining an existing codebase.)

    6. Re:Assembly by Anonymous Coward · · Score: 1

      I like to use the analogy that it's like building a house at the molecular level, where as higher-level languages would be like using materials such as lumber, steel and concrete instead of building it atom by atom (which theoretically could produce the same results, albeit after much more time and effort). For certain things, you need to work at a molecular level – it's a very powerful and important tool – but it's not the best way to build a house.

    7. Re:Assembly by Rockoon · · Score: 1

      There is more to assembly than knowing the instruction set. Producing good assembly is as much about knowing the architecture as the instruction set.

      If you couldn't beat a 1995-era compiler in 1995, then you must have been horrible.

      --
      "His name was James Damore."
    8. Re:Assembly by Rockoon · · Score: 0

      Reasonable c/c++ code can be as good as (or even better than) hand-tuned assembler.

      Lets turn its on its head a bit and suggest that a code generator can spit out C++ code that is as good as (or better than) even hand-tuned C++ code.

      Doesn't fucking make sense, does it? The reason you make this mistake with regards to assembly language is that you are ignorant. There is absolutely nothing that a compiler can do that cannot be done with "hand-tuned" (har har har) assembly. End of the fucking story.

      Basically, c/c++ code should nearly transform back into the equivalent assembler-generated code for almost anything, as long as your compiler is good.

      Somebody here thinks C is lower level than assembly. Dumb fuck. I have an idea.. when you have absolutely no idea what you are talking about... don't talk as if you do.

      --
      "His name was James Damore."
    9. Re:Assembly by Anonymous Coward · · Score: 1

      Sorry, 30+ years commercial assembly coder here (covering all the architectures you state and more) and I (respectfully) call bullshit.

      There may be some occasions where a compiler shaves cycles compared to good, hand coded assembly, but if all your output is beaten by a compiler at a steady 20%, that just means you don't really know how to code properly for the target.

      It's like a person writing a lean, properly coded app in VB which would outperform a shit implementation in C++ ...and 'assembler' is the system/application(s) that take your assembly mnemonic code and turn it into something that executes at hardware level, rather than hex editing (or whatever) the bits into place. You coded up to 1995 not knowing that???

      With no time constraints, a skilled coder and good assembler, assembly beats ALL in speed.

      All that said, C++ brings many benefits over asm these days in general computing... mainly speed of development and easier maintenance of large codebases, but sometimes assembly is the best tool for the job, or even VB for RAD projects... they're all just tools. The skill is in knowing which one to use for the problem and how to use it properly.

    10. Re:Assembly by flonker · · Score: 1

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

      I highlighted the bits everyone seemed to be missing.

    11. Re:Assembly by fyngyrz · · Score: 1


      Then you're doing assembly all wrong. Assembly language is quite easy to write in if you structure it properly.

      That said, it is an absolute bitch to read,

      Asm can be easy to read IF you have appropriate commenting skills. I have 68000 asm code for PCB full-bore autorouting here that is still easy for me to read, and believe me, the task is pretty darned abstract, so that's saying something. Likewise, I have asm code for audio signal processing, very easy to read, etc. After writing asm for a while and over at least a few architectures, you learn what you have to to to keep things understandable and maintainable.

      --
      I've fallen off your lawn, and I can't get up.
    12. Re:Assembly by fyngyrz · · Score: 1

      ASM is far higher than "molecular level", in fact, it's not all that far off from C (which is one of the benefits of C.) The real disadvantage of ASM isn't what the uninformed think it is -- the bogus claim that it doesn't get much done per line -- the main disadvantages are that each CPU requires learning a new architecture, and it isn't very portable unless the CPUs involved in the port implement asm or object level compatibility, and further, if you try to take advantage of that, you usually end up not using the cool features of later CPUs.

      But in the end, it's just about as easy to write in asm as it is in C, it isn't significantly more granular on a function-per-line basis, though it certainly allows you to use the available CPU resources considerably more efficiently than most compilers can even get close to.

      I recently had reason to go digging into the output of the GCC compiler when fed objective C... it was *horribly* inefficient. I was appalled at the resulting machine code, simply appalled. If someone had handed me that as a project in a "write a compiler" class, I'd have given it back with a remark like "you don't really want me to grade that, do you? You DO know that the CPU has more than one register you can use at a time, don't you? Try again." Yet this is the compiler that was used for production code in Apple's Leopard 10.5. Horrifying.

      --
      I've fallen off your lawn, and I can't get up.
    13. Re:Assembly by nitehawk214 · · Score: 1

      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.

      The derivative
      of the sine function equals
      the cosine function

      --
      I'm a good cook. I'm a fantastic eater. - Steven Brust
    14. Re:Assembly by 140Mandak262Jamuna · · Score: 1

      The derivative

      of the sine function equals

      the cosine function

      Words folded in

      three lines

      haiku. NOT

      You need an ah-ha moment, otherwise it is not a haiku, like:

      Boy pisses

      Mountain shakes

      Reflection in puddle.

      --
      sed -e 's/Chuck Norris/Rajnikant/g' joke > fact
  16. 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 Anonymous Coward · · Score: 0

      Yes, you are right, Java will only be slower 99% of the time. If someone says 100% he is an idiot.

    3. Re:Java is fast by wurp · · Score: 1

      Usually slower, yes. Enough slower to make you turn your nose up? You're just being precious.

    4. Re:Java is fast by jhoegl · · Score: 1

      Meh, in a world of IT where cost of servers in a small/med business is a very large concern, I think Ill go with the more efficient code.
      Disclaimer: I never liked the concept of Java and its oddly insane ability to have multiple security bugs at any given time.
      Good job Java, you slow down our systems and let hackers gain access. Way to keep small businesses down! (Sorry, I'm feeling very sardonic right now.)

    5. 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.

    6. Re:Java is fast by Dails · · Score: 1

      Thank you. The real reason Java is preferable to C++ (not always, don't jump down my throat) is the same reason that C++ is preferable to assembly (not always, don't jump down my throat): the less efficient code is more than made up for in the faster dev time. The dev time gap between Java and C++ is much smaller than C++ vs assembly, but the principle is the same.

    7. Re:Java is fast by TheRaven64 · · Score: 1

      I'll go with more scalable code. If my code isn't fast enough, but it becomes fast enough when I double the number of cores, then that's much better than code that needs a core that's twice as fast these days. One will be available in a year, the other won't. Of the languages that they tested, Go is the only one that encourages a programming style that comes close to linear scaling when you add more cores. Currently, the Go compiler is about on a par with the Objective-C compiler that NeXT shipped in 1988 (in terms of technology and optimisations performed), so there's also significant room for performance improvements there.

      --
      I am TheRaven on Soylent News
    8. Re:Java is fast by julesh · · Score: 1

      Meh, in a world of IT where cost of servers in a small/med business is a very large concern

      Additional cost of a better server to cope with GC overhead: ~$500, plus maybe $100 per annum extra power/cooling costs.
      Cost of developer time to deal with manual allocation on a nontrivial project: could easily come to $10000.

      Yes, off-the-shelf products designed to be used by large numbers of users should be written with manual memory management, because they can offset this cost into large numbers of customers. Most software out there is not used by this many people, though.

    9. Re:Java is fast by drolli · · Score: 1

      a) if you run number crunching things and need 20 servers (not unusual for even small size physical simulations), then you already can pay your programmer.

      b) You mean, the programmer should reimplement the some malloc for you or is it just enough if he uses an existing lib?

      For the latter, 100h seem exaggerated.

    10. 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...

    11. Re:Java is fast by Anonymous Coward · · Score: 0

      "In some situations $LANGUAGE will be faster than unoptimized $OTHER_LANGUAGE."

      This is true for all reasonable values of $LANGUAGE and $OTHER_LANGUAGE.

    12. Re:Java is fast by nitehawk214 · · Score: 1

      In some situations Java will be faster than unoptimized C++

      in some situations, Perl will be faster than unoptimized C++.

      For very large values of unoptimized.

      Though seriously it is all about choosing the best tool for the job. For some jobs it is C++, some Java, and some Perl. It seems to me like a research paper like this is mostly trolling. Lets get a grant by driving people red in the face with anger by dissing their favorite language. Apparently there is money to be made in flamewars. (Like the vi vs. emacs millionaires, I am sure.)

      --
      I'm a good cook. I'm a fantastic eater. - Steven Brust
    13. Re:Java is fast by mario_grgic · · Score: 1

      No that's not what they are saying at all. Why don't you just read the paper it's not that long you know.

      In fact, opposite is claimed. It took an expert to optimize C++ further to make it faster than Java, which got as fast as C++ as soon as someone used a more appropriate collections data type for the problem at hand.

      --
      As the island of our knowledge grows, so does the shore of our ignorance.
    14. Re:Java is fast by Puff_Of_Hot_Air · · Score: 1

      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.

      I don't agree with this statement. C++ may have a higher cost in training (I.e. the amount of time to reach high capability), and you may need to use a third party library such as BOOST to avoid re-writing some fundamentals (depending on what you're doing), but I see no reason why C++ takes any longer. At my work, we are a C#, C and C++ shop. The right tool is used for the right job, and C/C++ code takes no longer to write, nor has greater bugs.

      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]).

      C++ defines no threading model, and I'd suggest that Java out of box is also inadequate. .Net with parallels is the first with a general pratical model, that doesn't require enormous amounts of effort to acheive the equivalent of a single threaded performance. My point is that in the present day you are basically required to write your own asynchronous task based model that is capable of scheduling across multiple cores. Threads alone just don't cut it, and once youve written your task based asnychronous framework, you can reuse it to your hearts content (such as .Nets parralles).

    15. Re:Java is fast by sim82 · · Score: 1

      sorry, read my post (and the paper) again: "original c++" > "original java". After expert improvements (Jeremy Manson): "original c++" == "improved java" (see my orignal quote). I am assuming here that by "original C++ implementation" the article refers to the c++ version without any tuning (mainly no hash_set, which is not official standard, yet).
      My point is that, you can get pretty much the same performance out of java and c++, but you need a good java programmer to do that. On the other hand you need a failry good programmer to get a working c++ version at all.

    16. Re:Java is fast by Splab · · Score: 1

      It really amazes me how people on slashdot fail to read the sentences other people write, assume some arbitrary point and then goes on a rave about it.

      Read the sentence you quoted again, "For me...", see that bold word means it is something that applies to me as in an individual who isn't you, nor working at your company.

      The three Cs are better for you? Well all power to you then. Also, your last statement seems a bit out of context, you need to write your arguments down in a post rather than go over them in your head and only write down your conclusion. I have no idea what you are going on about...

    17. Re:Java is fast by Anonymous Coward · · Score: 0

      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

      While reading that bit about CPUs not getting any faster I thought of a quick reply saying WTF! of course they are. then I continued and noticed your further comment about threading and realized you had the right idea, just the wrong terms.

      CPUs have multiple cores... the cores aren't getting faster on the 'Moore's Law' curve like they used to when clock speeds kept going up and up. But, there are more cores being added to CPUs so CPUs are still getting faster because they can perform more computations in x time.

    18. Re:Java is fast by Anonymous Coward · · Score: 0

      If that's your criteria, then you need to look into Common Lisp, Ruby or Perl.

    19. Re:Java is fast by Anonymous Coward · · Score: 0

      Thank god you aren't writing the linux kernel.

    20. Re:Java is fast by epine · · Score: 1

      Anyone clinging to the notion of an "unoptimized" compiled language is using language as a weapon rather than a tool for thought.

      How anyone still believes C is faster than C++ is beyond me. C is very nearly a proper subset of C++. This would put C and C++ on par, if C++ only added RTTI and exceptions and virtual pointers to the C language stew.

      But in fact, C++ adds compile time code reduction through the template facility, operating at a higher level of abstraction than the compiler can access, because the abstraction captures additional programmer intent.

      I guess a sufficiently determined programmer can hand compile Boost:Spirit to C code if the dude has nothing better to do than win a language war.

      I was speaking recently with an irrigation specialist who described a 100 hectare irrigation project where the intake fouling problem has been solved by removing the intake filter. The crafty farm hand reported that the pump was now generating maximum pressure. Problem solved, from that perspective. Unfortunately, he didn't have a handy dial to report that no water was flowing. 100 hectares of replaced drip hose later, the pressure had gone way down again. You just can't win.

      In these language wars, there's never a shortage of people rushing in to unclog the intake filter.

    21. Re:Java is fast by PitaBred · · Score: 1

      So... coding should be left to the experts? I wholeheartedly agree ;)

    22. Re:Java is fast by Anonymous Coward · · Score: 0

      Almost every modern general purpose language is able to produce testable and maintainable code.
      The maintainability of the code is a function of the coder and the environment he's forced to work in, not the language.

    23. Re:Java is fast by Anonymous Coward · · Score: 0

      well, I think this is kind of true for c++. Java has an amazing ability of letting you get away without "caring too much" about lots of details. That is ok, if you don't expect maximum performance. In c++ you implicitly have to care about a lot more stuff (e.g., resources) just to get your code through the compiler...

    24. Re:Java is fast by funky_vibes · · Score: 1

      I cannot agree.
      The silver bullet developers are looking for in order to save dev time just isn't there, no matter which language you pick.

      If you write software carefully in C, C++ or java, you tend to end up with about the same amount of code and a similar amount of effort.

      Threading, just like any new paradigm, is fundamentally harder code to write, no new invention is going to make it easier, unless you are hiding problems.

      The problem is that the level of acceptance for buggy Java code is *way* lower than for C++ for example. People tend to ship broken products early.
      An (un/all)caught exception or one that doesn't produce a useful user message is still a crash, no matter how you look at it.

      I pick C++ simply because it's tried, has more libs, better code and implementations going for it. And, as an added bonus, it isn't slow by design.
      Also, not all developers have the liberty of wasting memory such as a java environment mandates.

    25. Re:Java is fast by Prune · · Score: 1

      C++0x brings in a good and well-rounded threading model, while at the same time the optimization nuts still have the flexibility of using custom synchronization primitives which leave the OS/language-provided ones in the dust (see http://locklessinc.com/articles/ for numerous examples). Besides, if you really wanted to solve problems the fastest, in terms of programmer time, then you should be using Lisp, as has been established in contests between users of different languages for the same given problems.

      --
      "Politicians and diapers must be changed often, and for the same reason."
    26. Re:Java is fast by mcrbids · · Score: 1

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

      Depending on the job, there are numerous things to consider, and for some things, performance is one of them. For example, if you want to write a graphics intense video game, performance is most definitely a primary factor.

      --
      I have no problem with your religion until you decide it's reason to deprive others of the truth.
    27. Re:Java is fast by MikeBabcock · · Score: 1

      It really amazes me how people on slashdot fail to read the sentences other people write, assume some arbitrary point and then goes on a rave about it.

      Happens all the time. Nobody seems to realize that different programmers are like different languages; they're different and often have different uses ... although some just suck.

      As a *nix guy, I always laugh about the C/Java debate and wonder where my shell scripts, PERL, Python and quicky awk programs fit into the debate.

      That is to say, I often solve a programming problem with PERL, Awk or Python faster than I'd choose the appropriate #include's for a C* program. Not large programs obviously, but an awful lot of system automation, reporting, maintenance and other code that seems to be done with compiled languages on Windows systems just seems faster to write and easier to maintain in special purpose interpreted languages.

      --
      - Michael T. Babcock (Yes, I blog)
    28. Re:Java is fast by Puff_Of_Hot_Air · · Score: 1

      It really amazes me how people on slashdot fail to read the sentences other people write, assume some arbitrary point and then goes on a rave about it.

      Read the sentence you quoted again, "For me...", see that bold word means it is something that applies to me as in an individual who isn't you, nor working at your company.

      Oh I'm sorry. I see my mistake now; by adding "for me", you are allowed to make statements that cannot be challenged. "It's my opinion man".

      For me, people that unreasonably hide behind an 'opinion' in an attempt to exclude debate are arseholes; but that's only my take on it.

      The three Cs are better for you? Well all power to you then.

      You have a mistaken assumption. I use C# at work, because that is my work, but I don't see any qualitative difference between it and Java. I was using it as an example of having used both forms of tools. YMMV.

      Also, your last statement seems a bit out of context, you need to write your arguments down in a post rather than go over them in your head and only write down your conclusion. I have no idea what you are going on about...

      It doesn't really surprise me that you no idea about what I'm talking about, because you clearly had no idea what you were talking about in your initial comment. I'd try to educate you, but I sadly think it'd be a waste of time.

    29. Re:Java is fast by wurp · · Score: 1

      Yeah, that's why I copped out and said "likely". I personally have rarely worked on code in which CPU performance was a big factor - less than 1% of my time. I have been programming professionally on a large variety of projects for about 17 years.

      I totally agree with you for the kind of work you mention, with the caveat that you should ALWAYS profile before doing low level optimization.

  17. 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.

    1. Re:piss n vinegar by Rockoon · · Score: 1

      Of course its going to be a C that wins. It's pushed close to the iron.

      Yet another C programmer that thinks C is "close to the iron"

      Do not confuse C's lack of high level features with "low level" .. C's lack of high level features just means that it lacks high level features.. it does not mean that it has low level features.

      Aside from pointers, C has exactly 0 low level features, and even then it cannot be reliably coerced to take advantage of all the complex addressing modes of a real architecture (translation: C's abstract machine has no addressing modes, or flags, or anything else low level.. hell, you can't even get the double-wide result of a multiply that is produced by every x86 since the 8088, or get both the quotient and remainder out of the x86 division instructions, or leverage any of the instructions specifically tailored to arbitrary precision math, or... you get the point?)

      --
      "His name was James Damore."
    2. Re:piss n vinegar by fyngyrz · · Score: 1

      Actually, I think we're dealing with two completely different definitions of "close to the iron here". Nothing wrong with yours (low level architectural feature access), but yours isn't the usual meaning, either. The usual meaning is that a line of c produces easily predictable results for a particular architecture, and therefore someone who knows the CPU architecture, compiler habits, and c itself can do a good job of keeping the code efficient within the bounds of what the compiler does. This becomes more and more difficult as the compiler sophistication upscales, eg with C++, and that's why c, rather than c++, gets the accolade.

      Also, an argument could be made for some versions of C having low level architectural feature access by virtue of simply being able to say #asm at any time and properly utilizing the compiler's version of the #asm/#endasm interface. Although as far as I'm concerned, if you're going to do that, you probably should have been writing in asm anyway...

      --
      I've fallen off your lawn, and I can't get up.
    3. Re:piss n vinegar by Rockoon · · Score: 1

      Also, an argument could be made for some versions of C having low level architectural feature access by virtue of simply being able to say #asm at any time and properly utilizing the compiler's version of the #asm/#endasm interface. Although as far as I'm concerned, if you're going to do that, you probably should have been writing in asm anyway...

      #asm is not part of the C definition, and there is more than one BASIC compiler than has inline assembler (as well as hacks for BASIC compilers that do not support it, such as VB6 using TweakVB)

      None of Microsoft's 64-bit compilers support inline assembler at this point.

      The usual meaning is that a line of c produces easily predictable results for a particular architecture

      Many languages have this predictability in the same sense that C does, including BASIC and Pascal. Nobody is calling BASIC "low level." The only people calling C "low level" are C programmers and those that believe the hype.

      --
      "His name was James Damore."
    4. Re:piss n vinegar by Anonymous Coward · · Score: 0

      In the old days - you know before Microsoft - There was a little saying:
      AIDA is for criminals
      Pascal is for students (read novice)
      PL1 is for adults and ...
      C is for consenting adults
      Yes faster counts, but it is not usually the primary consideration for language
        adoption. It is far more important to make the thing work properly at a price
      that you can afford. Non-functioning and fast is just useless! OK - so functioning and slow slow slow is also useless!
      Ahh the fun of it all; you get to make a design decision; be prepared to justify your
      decision!

    5. Re:piss n vinegar by ImprovOmega · · Score: 1

      Aside from pointers, C has exactly 0 low level features, and even then it cannot be reliably coerced to take advantage of all the complex addressing modes of a real architecture (translation: C's abstract machine has no addressing modes, or flags, or anything else low level.. hell, you can't even get the double-wide result of a multiply that is produced by every x86 since the 8088, or get both the quotient and remainder out of the x86 division instructions, or leverage any of the instructions specifically tailored to arbitrary precision math, or... you get the point?)

      C has exactly one low level feature that allows you access to all of that:

      asm {
      //code goes here
      }

      Other languages tend to sacrifice that for enhanced portability.

    6. Re:piss n vinegar by Phantom+of+the+Opera · · Score: 1

      Of course its going to be a C that wins. It's pushed close to the iron.

      Yet another C programmer that thinks C is "close to the iron"

      No, I'm a frenetic scripter. I do perl, son. When I don't have time for the dictionary perfect definition, I'll use what people will probably understand anyway and know its not exact.

    7. Re:piss n vinegar by slimjim8094 · · Score: 1

      Low level, in this context, means that there are a very few number of abstractions between the C and native assembly instructions. C++ adds an object model that the computer doesn't deal with, Java is of course a bytecode, and so on - but C maps very closely onto (non-exotic) hardware. Loops are 'jmp's, functions are 'call's, structs are a format for memory layout, pointers are raw memory addresses, and so on. It's quite straightforward to hand-compile most C code. Not so for C++, unless you feel like hand-coding vtables.

      You're talking about something completely orthogonal to the level of abstraction. Unavailable specific processor features has nothing to do with it - if you used a 20 year old x86 assembler it wouldn't support SSE2, but would this make the assembly it supports not "close to the metal"? On the flipside, you could write a Python module that directly exposes the SIMD instructions as vector math ops, for example, and it would still be high-level. By car analogy, not having access to the valve timings doesn't make a manual transmission high-level shifting. It's higher-level than reaching in and moving gears around, but not by much.

      And in any case, modern compilers know how to use SSE and MMX and other special features, particularly if you tell it so.

      --
      I have developed a truly marvelous proof of this comment, which this signature is too narrow to contain.
    8. Re:piss n vinegar by PaladinAlpha · · Score: 1

      The damned Linux kernel is written in C. Is that low level enough for you?

      C is absolutely a low level language. There are lower level languages, sure (assmebly, and, uh, hmm... assembly?) but C allows you direct unmanaged memory access and pointer manipulation. Moreover, there are constraints on the complexity of code that C can generate without telling you. This is not true of the languages you are trotting out.

      I'm sure this is somehow some "Java is the best systems language" bullshit that you're leading up to trying to trot out, but C is and always has been a very-nearly-ideal systems programming language, as in it's what sits between you and the hardware. If that's not low-level then what, pray tell, is?

    9. Re:piss n vinegar by funky_vibes · · Score: 1

      If you're saving development time, performance isn't the only thing you're selling out. Most likely you're selling out one or all of the following: robustness, user-friendliness, memory usage, security, completeness.

  18. 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?

    1. Re:Average Programmers... by phantomfive · · Score: 1
      I don't think that quote is right. If you look at the optimizations done in the C++ version, their main performance increases was made by using hash_map instead of map. This is easily within the sophistication of the average programmer, at least, no harder than their Java optimizations, which were:

      "Replaced HashSet and ArrayList with much smaller equivalent data structures that don’t do boxing or have large backing data structures."

      Also, I don't think the test was quite fair for Java. Here is what the paper says:

      Note that Jeremy deliberately refused to optimize the code further, many of the C++ optimizations would apply to the Java version as well.

      In other words, partially optimized Java is slower than fully optimized C++? Well isn't that amazing. If they're going to do it, they ought to optimize it all the way.....

      --
      "First they came for the slanderers and i said nothing."
    2. Re:Average Programmers... by sourcerror · · Score: 1

      Of course on Slashdot everyone is above average.

    3. Re:Average Programmers... by mario_grgic · · Score: 1

      Market pressure to deliver faster happened. Programming escaped from the confines of University labs and got generally useful to people. So they started having desires for functionality and features. Now languages that allow faster time to market dominate in web space. Talking about speed here is all about how fast can I push this change live. And here C++ is insanely slow language. Java is really slow, slow enough that some companies are abandoning it for much much faster Ruby. As you all figured out the "speed" here is the speed of innovation on your product. Pushing out new feature goes from one week in Java to about a day in Ruby and runtime performance is rarely an issue.

      --
      As the island of our knowledge grows, so does the shore of our ignorance.
    4. Re:Average Programmers... by syousef · · Score: 1

      '...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?

      People needed to get stuff done quickly and cheaply. That's what happened. Hey they spent a small fortune landing on the moon using less memory and CPU than today's desktop calculators. But a business running a web shopfront or a bank doing transaction processing doesn't have those kinds of resources. So they cut corners. If you can buy a cheap machine that does things 1000x more quickly it makes no sense to spend 100x as much for a team of programmers who understand the code well enough to get a 50-100% improvement on code speed. You just buy the "ridiculous memory and processing speed available in today's computers" and move on!

      --
      These posts express my own personal views, not those of my employer
  19. Best permorming language on the market? by Anonymous Coward · · Score: 0

    And they test against only three other languages? What kind of BS is that?

    So what about C, Fortran, Ocaml, CL, Haskel? Last I heard C & Fortran were every bit as fast as C++ (if not faster) and the other three can produce very fast code.

  20. 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."
    1. Re:Nope - Java refused to go in to the ring by Anonymous Coward · · Score: 0

      I just read this too. What kind of research is this then? Crazy.

  21. JVM issues, really. by Anonymous Coward · · Score: 0

    To a great extent, this is not about the superiority of C++ compilers, but about the limitations of the JVM as a compiler backend (and possibly, if I read it right, some problems with the garbage collector). Go is still too much under development to be a realistic comparison point for high performance code.

    For example, one of the C++ tuning optimizations that they used was changing a linked list of pointers to basic blocks to a vector of basic blocks. This eliminates a level of indirection, requires fewer allocations/deallocations, and probably has better caching behavior. But the JVM cannot even produce the same representation due to its incapability of expressing a flat sequence of records/structs (unlike, say, the .NET CLR). They were also using some handcrafted internal Google data structures for tuning and some fairly low-level optimizations.

    I doubt that the results would be as lopsided if the comparison occurred with a language with a more versatile IR and a mature backend (such as OCaml).

  22. Moot Point by Anonymous Coward · · Score: 1

    Assembler is by far the best performing language. But most of the time, Java performs well enough with modern hardware, so that performance becomes a moot point. As the article mentions, Java is the easiest to implement. It also has the advantage of being cross platform, something which the article doesn't address.

    1. Re:Moot Point by dmbasso · · Score: 1

      "Java compiler", "Python interpreter", "C++ compiler", "Assembler", they are all good languages, don't you think?

      --
      `echo $[0x853204FA81]|tr 0-9 ionbsdeaml`@gmail.com
    2. Re:Moot Point by VortexCortex · · Score: 1

      HAHA -- Sure. Hey GCC complies FORTRAN, and a slew of other "languages" -- What about giving Borland and Microsoft a chance at these "tests" too? I mean, if we're testing a language in TFA, shouldn't we use a variety of runtime libraries and compilers in order to find the real "average" performance?

  23. 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.

    1. Re:C++ is like sex in high school... by gweihir · · Score: 1

      I think you have it perfectly right. Although I started using Python some time ago and do not believe in static type-safety anymore. Even before that, having learned OO with Eiffel, I found the standard type model as used in C++ far too restrictive.

      As to bad C++ programmers, no surprise here. C++ makes it hard to see what the compiler actually does and what is an effective use of the language and what not. So most people programming C++ actually have no clue what they are writing and fall back to a set of "templates" in "that is how everybody does it". Not pretty. In java you have less freedom and consequentially the compiler and libraries can be better optimized and opportunities to screw up are fewer. They still exist on a higher level. It is astonishing how many people have no clue at all about algorithmics.

      --
      Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
    2. Re:C++ is like sex in high school... by syousef · · Score: 1

      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.

      No one? Really? You're alone in the world in your unique understanding of C++ are you? Either you're a freaking genius, or you're never had the good fortune of working with competent people, or you highly overvalue yourself. Guess which one I'd be banking on. You are sounding like a cartoon super-villan: "I'm surrounded by idiots!". Oh and if NO ONE else understands what you're saying, it's because you can't communicate well, not because they're all stupid.

      --
      These posts express my own personal views, not those of my employer
    3. Re:C++ is like sex in high school... by Shados · · Score: 1

      A select few companies grab the vast majority of worthwhile programmers (regardless of languages) with superior salary and advantages.

      If you don't work for one of those companies (who, on top of the good programmers ,also have tons of bad ones, don't get me wrong), then the odds of you seeing a good software developer/architect/manager/whatever in your team drop drastically. Its not impossible, but its rare enough that someone could go their entire career without seeing one.

      At least, thats what i gather between the experience of my wife (also a software engineer) and mine's over the last decade working for 20~ companies and institutions and looking at market trends.

    4. Re:C++ is like sex in high school... by Anonymous Coward · · Score: 0

      Can you do me a favor and read the next line, after the one you quoted? I'm not denying that good people exist, only that I have worked with roughly zero of these people.

    5. Re:C++ is like sex in high school... by shutdown+-p+now · · Score: 1

      I know from reading books and papers and Internet that people who "get" C++ exist.

      Er, so who's the third guy? ~

  24. real C by Anonymous Coward · · Score: 0

    If you speedtune c++ enough it will resemble pure c. In that case you want c to get rid of the annoying c++ ABI and for a further increase in speed.

  25. Performance often not critical by Frans+Faase · · Score: 1

    The cases in which performance is critical, are getting less and less, now that hardware is getting faster and faster. Not strange that Microsoft is focussing on JavaScript and HTML5. It seems that at the moment the greatest effort in performance improvement is put into JavaScript.

    1. Re:Performance often not critical by kvvbassboy · · Score: 1

      I agree. But you are not going to be solving combinatorial problems in Javascript anyhow.

    2. Re:Performance often not critical by Anonymous Coward · · Score: 0

      The cases in which performance is critical, are getting less and less, now that hardware is getting faster and faster

      How's the weather on Mars? 'Cause here on Earth, hardware isn't getting faster, it's getting more parallel.

      I get really tired of the "performance is not important" lie. When I start MS Word and it takes 5 seconds for the splash screen to go away, that pisses me off. I don't care that it would have taken 6 months to fix that before I could have 2010, it sucks and you suck.

      I also love the "developer time is more expensive" rationalisation; guess what? If it costs $100,000 to employ a good developer and you pass on spending 1 month optimising a program used by 10000 users on their job who earn a mean income of $50,000 then all you have done is shift costs from the present to the future. If that optimisation would have reduced the time of a common task of 10 secs to 2 secs and it is performed 100 times a day we have:
      $100,000/12 (months) = $8,333.33 per month
      $50,000/12 (months) = $4,166.67 per month
      20 (days) * 100 (ops) * 8 (time-wasted) = 16,000 secs per person per month [4 hours]
      20 (days) * 8 (hours) * 60 (minutes) * 60 (seconds) = 576,000 secs per person per month
      16,000 / 576,000 = 2.7% of the time at work
      $4,166.67 * 2.7% * 10000 (users) = $1,125,000.90 (1 million wasted dollars per month)

      Congratulations, you saved yourself a penny while forcing everyone else to spend a dollar. Also notice that this cost is recurring unlike the developer's salary which is one-shot.

      Not strange that Microsoft is focussing on JavaScript and HTML5.

      Yes, because Microsoft has always been the gold standard of performance. And it's totally got nothing to do with HTML5 being the current buzzword tech, sure.

      It seems that at the moment the greatest effort in performance improvement is put into JavaScript.

      When you start at "shit", getting to "not wanting to rip my hair out" is not hard, "acceptable" is still some way off. [WhyTF don't browsers just take bytecode produced by any language a developer feels like writing a compiler for? A VM is easier to optimise and allows competition in compilers. It also removes the stupid "Let's do the slow lex and parse on this script over and over every time we open this site even though the code hasn't changed" problem.]

    3. Re:Performance often not critical by Anonymous Coward · · Score: 0

      This depends on what kind of development you do. In the embedded world there is both cost and speed which are taken into account. And you need the abbility to tune both memory and speed. Or maybe just rely on the system not to have to much overhead.

      And the saying that hardware is getting faster and faster has been said for so long and in the embedded field nothing much has changed. More ppl and companies use embeeded programming so the need for performance and tunability is getting higher.

    4. Re:Performance often not critical by fyngyrz · · Score: 1

      JFC!!! mod parent up UP UP for the spot-on "performance is not important" rant

      --
      I've fallen off your lawn, and I can't get up.
    5. Re:Performance often not critical by ceoyoyo · · Score: 1

      Wonderful that we can use our fancy technology to cover up our own sloppiness.

      Five years ago I remember Slashdotters complaining about how faster CPUs were just being used to compensate for Microsoft bloat.

  26. Ehhh... I... don't believe that. by eddy · · Score: 1

    I don't know about that, maybe it was faster than Borland C++, but I did a lot of work (disassembly) on Borland Pascal compulation units and executables back in the day, and the code was horrible. HORRIBLE. Didn't even have the most basic peephole-optimizations (though someone wrote an external application to do that). It was fast to compile though, due to being one-pass, but that right there sacrifice optimizations.

    So if TP/BP was faster than BC++, it was only because BC++ must have been even worse than I can imagine.

    --
    Belief is the currency of delusion.
    1. Re:Ehhh... I... don't believe that. by Darinbob · · Score: 1

      The biggest drawbacks I see with C++ is the style of programming used. Heavy templated use, heavy STL, heavy reliance on exceptions, etc, all of which tends to bloat up the code to no end (there are ways to do this right but I rarely see it done by the "memory is cheap" crowd"). So the naively compiled Pascal program may have a lot more locality of reference which improves the performance despite the lack of tweaked assembler.

    2. Re:Ehhh... I... don't believe that. by eddy · · Score: 1

      I'm not sure the STL even existed at the time we're talking about. At the very least it wasn't widely used, so in the context of this dicussion it's a non-issue.

      --
      Belief is the currency of delusion.
  27. seriosuly? by blarghmaster · · Score: 1

    trollfood / fanboi-food post is obvious debating the effectiveness/awesomeness/speediness of a programming language is like saying "apples are better cuz oranges have hidden pips"

  28. Google specific code by Anonymous Coward · · Score: 0

    From the research paper:
    "In all implementations, we use the default, idiomatic data structures in each language, as well as default type systems, memory allocation schemes, and default
    iteration constructs. All four implementations stay very close to the formal specification of the algorithm and do not attempt any form of language specific optimization or adaption."

    "We believe that this approach highlights features and characteristics of the languages and allows an almost fair comparison along the dimensions of source code complexity, compilers and default libraries, compile time, binary sizes, run-times, and memory footprint."

    From the research paper:
    "At time of this writing, the cpp_pro version depended strongly on Google specific code and could not be open-sourced."

    We aren't given the source code so I can only speculate, but the above comments don't seem to jive. If you are trying to only use default libraries, types, etc of the languages and not use language specific optimizations or adaptations, then I have a little trouble coming up with how you could have "Google specific code" upon which the C++ improved version depends.

  29. It's not for everyone, though. by Tarlus · · Score: 1

    Nope, C++ certainly not for everyone. But the most powerful tools rarely are.

    --
    /* No Comment */
    1. Re:It's not for everyone, though. by fyngyrz · · Score: 1

      The most powerful tool -- and the one with the most precision -- is asm. And it certainly isn't for everyone. What YOU probably meant to say is "C++ and other tools of increasing abstraction aren't for everyone."

      --
      I've fallen off your lawn, and I can't get up.
    2. Re:It's not for everyone, though. by Tarlus · · Score: 1

      Nah, in this context (comparing against garbage-collected and OO-centric languages), one could put both C++ and ASM together into the 'most powerful tools' category.

      --
      /* No Comment */
  30. Java threading by sourcerror · · Score: 1

    You mean suspend/resume? That was deprecated like 10 years, but functions required to do it right were in from the beginning (since 1.0).

    1. Re:Java threading by Splab · · Score: 1

      Nah, that's before my time as a "professional" programmer. Back when I was studying we had a teacher, Brian Vinter, whom used to love bashing Java - one of his favorite presentations was "Wot, no chicken?" (or starving philosophers if you will).

      See this: http://www.cs.kent.ac.uk/projects/ofa/java-threads/0.html

  31. business is different by holophrastic · · Score: 1

    Many talk about time to develop, and certainly C/C++ sucks in that capacity. And many talk about code complexity and liklihood of bugs due to memory management, and certainly there's much to be said there too. But C/C++ fails me in one very simple business category: code robustness.

    Every project I work on has clients doing one very important thing -- turning the entire thing upside-down and backwards three times. In C/C++, I'd get to start from scratch every time. In Perl, I get to shuffle a few lines of code to invert a feature, and that's it.

    It's really painful to write C/C++ code in a flexible manner for future arbitrary upgrade. And that's what I need in order to run my business. The other speeds can be made up by throwing money at additional hardware. I can't tell a client that it'll take months to make a decent upgrade, nor charge them for that much time.

    1. 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.
    2. Re:Business is different by shutdown+-p+now · · Score: 1

      When people write "C/C++", they usually mean "C and C++" (because a lot of things - and this one in particular - do indeed apply to both), not some kind of a merged superset.

    3. Re:Business is different by smellotron · · Score: 1

      When people write "C/C++", they usually mean "C and C++"

      It's a bad habit that poisons your mind, because saying it enough may make you forget that it's not true. What appears to be lacking is an appropriate and popular term for the family of languages with similar characteristics. This is much like "Romance languages" vs. "Spanish/Italian": the former is universally recognized as a broad category, whereas anyone claiming fluency in the latter had damn better well be able to speak both languages.

  32. Business is different by holophrastic · · Score: 1

    Many talk about time to develop, and certainly C/C++ sucks in that capacity. And many talk about code complexity and liklihood of bugs due to memory management, and certainly there's much to be said there too. But C/C++ fails me in one very simple business category: code robustness.

    Every project I work on has clients doing one very important thing -- turning the entire thing upside-down and backwards three times. In C/C++, I'd get to start from scratch every time. In Perl, I get to shuffle a few lines of code to invert a feature, and that's it.

    It's really painful to write C/C++ code in a flexible manner for future arbitrary upgrade. And that's what I need in order to run my business. The other speeds can be made up by throwing money at additional hardware. I can't tell a client that it'll take months to make a decent upgrade, nor charge them for that much time.

  33. Java: -XX:+CycleTime ? by Anonymous Coward · · Score: 0

    In the paper they write, that they used the JVM-Option "-XX:+CycleTime" alongside others. I couldn't find any reference on what CycleTime does, nor does my Oracle JVM 6u24 recognize it. Does anybody have an idea, what this option is for, and if it's actually available in regular JVM builds?

  34. This just in by drb226 · · Score: 1

    Lowest-level language with careful tweaking yields best performance. Film at 11.

  35. Homoiconicity by sourcerror · · Score: 1

    " Functional languages should excel at this, they have been ruling the program transformation/analysis space for a long time."

    I think the key is homoiconicity, not functionalness. Prolog isn't a functional language, and it's mainly used for domain specific languages/one-off compilers.

  36. Can't generalize from this study by inglorion_on_the_net · · Score: 1

    Google has released a research paper (PDF) that suggests C++ is the best-performing language on the market.

    No, they didn't. They compared four languages (C++, Go, Java and Scala) using a single algorithm, and two implementations (initial and improved) per language. Out of those, the optimized C++ turned out to be the fastest and the least memory hungry, whereas the improved Scala version used the least source code, and the improved Go version compiled the fastest.

    None of this allows generalization to "best-performing programming 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.'

    This is a very important point. If you are Google, you probably have developers who can do this kind of tuning, and you will probably benefit from it (the developer effort is expensive, but inefficient software may well be more expensive at Google's scale).

    In general, though, what you want to consider is not only the best performance that has been produced by the world on a single problem, but also the performance on different problems, the variation in performance between implementations, the average performance, and the development time.

    In 2000, Erann Gatt (now Ron Garret) published a paper (PDF) that showed the results of comparing 16 implementations written by 14 programmers, in C or C++ (lumped together), Java, and Common Lisp or Scheme (lumped together). These results show that the fastest programs were written in C or C++, Lisp produced the fastest programs on average, and offered the least variation in performance. Lisp also offered the shortest development time on average.

    Of course, this is old data. If anyone has performed a similar study more recently, or including different problems to be solved rather than a single one, I would be very interested.

    Meanwhile, the Computer Language Benchmarks Game compares many language implementations across several different tasks, with multiple programs for each task, and shows that the results differ depending on exactly how you measure.

    Apparently, if you want the fastest programs, you should go with C, C++, Ada, ATS (Fortran, Common Lisp, and Python also produced fast programs, but weren't as good on average). If you want short programs (which may be expected to correlate with short development time), you might want to go with Ruby, Python, Perl, Lua, or JavaScript. If you want short development time, but also reasonable performance, then Go, Scala, or Haskell may be good choices (or you could go the time-tested route of writing what you can in rapid development languages, and the parts that need to be fast in high-performance languages).

    --
    Please correct me if I got my facts wrong.
  37. Scala is fast! by Anonymous Coward · · Score: 0

    To me the results of the Scala implementation are more noteworthy than the comparison between C++ and Java. If I read The Fine Paper correctly the Scala version is more concise, faster and has a lower memory footprint than the Java version. Since both compile to Java bytecode and run on the same VM this really is remarkable.

  38. 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.

    1. Re:Not a language shootout.... by Anonymous Coward · · Score: 0

      Its much simpler than that. Its an advertisement for Go.

    2. Re:Not a language shootout.... by petermgreen · · Score: 1

      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?

      Well JNI is an interface to specially written native code (in principle I belive any language that compiles to native code and supports the platforms standard ABI can be used, in practice you will probablly find it painful to use anything except C or C++). So a program that uses JNI is no longer pure java, it's a mixed language program.

      JNA is a more borderline case because it allows your program to remain pure java while directly using native code libraries without having to write specific peices of native code as a bridge between the native library and the java application.

      --
      note: i'm known as plugwash most places but i screwd up registering that here somehow in the past and now can't register
    3. Re:Not a language shootout.... by Anonymous Coward · · Score: 0

      I'm sorry but you're hiding your knowledge from the eighties behind techno-babble. The reason why in some (not so common but still) tests Java outperforms C and C++ is because, precisely, it's not "compiled to machine code" but "constantly re-compiled to machine code" using their HotSpot real-time-(re)compiler. The hotspots are optimized to better, smaller, faster, machine code while the less used path aren't.

      In some cases the HotSpot compiler produces machine code that's faster than what any human could reasonably produce.

      You conveniently forgot to mention that because it doesn't fit well in your (pathetically +3 modded) analysis straight from a 1st grade CS book from the early eighties.

      Seriously?
       

    4. Re:Not a language shootout.... by antifoidulus · · Score: 1

      Hey shithead, if you are going to mouth off, you should at least read the fucking article and read the fucking post before doing so, OK? It's obvious by your post that you're head is stuck too far up your own asshole to have read either of them. I specifically mention the JIT code in my post, and mention specifically what they wrote in the article. Natively compiled code is going to be optimized differently than JIT compiled code, and those differences are going affect the performance. FUrthermore, the optimizations are going to depend on the VM you are using. You're "counterpoint" proves my point exactly. Before someone of such low intellect tries to master a first year CS course, maybe you should try mastering first grade reading comprehension. Because a dumb fuck such as yourself obviously has shown themselves to be incapable of basic reading and comprehension skills.

    5. Re:Not a language shootout.... by shutdown+-p+now · · Score: 1

      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?

      If the language specification for Ada mandates those checks, then yes, it stops becoming Ada.

      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?

      The program that makes a call via JNI does not stop being a Java program, but any JNI code thus called should not be counted as part of that Java program. If it's strictly necessary for the operation, then you can't talk of the resulting aggregation as "Java program".

    6. Re:Not a language shootout.... by tepples · · Score: 1

      but when you use JNI does your program stop being a Java program?

      Programs that use JNI will not load in those platforms that expect 100% Pure Java. These include, for example, applet-capable web browsers and MIDlet-capable phones. A lot of these platforms expect all native code to have been digitally signed by the platform's curator.

    7. Re:Not a language shootout.... by Anonymous Coward · · Score: 0

      agree with u, ultimately we execute "logical constructs" which a CPU understands. The fastest program for a given CPU/memory combination will therefore always be pretty close to one or maybe two possible options, depending what we are trying to do. Higher level languages simply map "our constructs" (something we are more comfortable "talking" with the CPU in" to these final "language of the CPU". If there is problem, it;s as much in this "conversion" process rather than what you are "talking in"...

      Guy to computer: hey I am talking to u in Java, why is it taking so long for u to understand...
      Computer to Guy: because there is a bloody interpreter in between u n me stupid.. who keeps correcting & checking everything u say...

  39. ASM by Bert64 · · Score: 1

    Surely assembly would be the highest performing language, while also requiring the most extensive tuning efforts and a level of sophistication not available to the average programmer...

    More importantly tho, would be to know which language provides the best balance between performance and work required?

    And ofcourse another thing to consider, is how often the code will run.. Not much point saving an hour writing it, only to waste 500 hours of cpu time running it.

    --
    http://spamdecoy.net - free throwaway anonymous email - avoid spam!
    1. Re:ASM by ceoyoyo · · Score: 1

      "More importantly tho, would be to know which language provides the best balance between performance and work required?"

      A combination of more than one. Python with C modules, for example.

  40. Memory bloat by Knightman · · Score: 1

    I think the biggest problem with Java is the memory bloat. A lot of the developers that work with Java have a very limited understanding how things work under the hood. This usually leads to programs that include references to "good to have" packages/frameworks that contain some functionality they need which in turn leads to memory bloat. If you then have a java-program that needs to run in multiple instances you don't gain the functionality of one memory-image many processes most OS's support. (One of the core-features that Dalvik has if I remember correctly).

    Since Java have GC a lot of Java-folks seems to think memory use isn't something you should care about since the "GC" can handle it for them. This leads to bad coding-practices. No matter the language you should always know the scope of an objects life.

    IMHO it doesn't matter what language you are using as long as you know what you are doing. Java often get "bashed" from C/C++ programmers but I think that's because Java as a language has a lower threshold with regarding to prerequisite knowledge about CS and is easier to learn, which produces programmers that thinks about computers as a mysterious black box that "just works (mostly)" and the code reflects that in functionality and poor performance.

    --
    --- Reality doesn't care about your opinions, it happens anyway and if you are in the way you'll get squished.
    1. Re:Memory bloat by sourcerror · · Score: 1

      Well, Firefox 2.x was pretty slow, and leaked a lot of memory, and it wasn't written in Java ... Also, I don't think that Firefox devs were subpar. If the application gets complicated enough, chances to mess up memory freeing are high.
      Also a lot of people don't know that the JVM allocates predetermined amount of memory from the OS from startup, and you can change it in proper command line options. So the memory footprint depends a lot on how the application is deployed.

    2. Re:Memory bloat by Rockoon · · Score: 1

      A lot of the developers that work with Java have a very limited understanding how things work under the hood.

      This is just as true for C and C++ programmers. Most programmers know the abstract machine that their language defines and thats it. The only thing C programmers are bringing to the table is a better understanding of pointers.

      --
      "His name was James Damore."
    3. Re:Memory bloat by equex · · Score: 1

      I used to really think Firefox was written in Java. (Before I learned it was XULRunner)

      --
      Can I light a sig ?
    4. Re:Memory bloat by mario_grgic · · Score: 1

      For the kinds of things Java is used for memory bloat is not important (just install 64 GB on your server, it's only $2000 anyway). The biggest problem with Java is GC pause times. Your server will stop the world for 30 seconds to 2 min. while it collects the garbage. And that's usually not acceptable and a real problem that everyone runs into sooner or later that has no good solution.

      --
      As the island of our knowledge grows, so does the shore of our ignorance.
    5. Re:Memory bloat by SomeStupidNickName12 · · Score: 1

      30 to 2 mins? That never happens. Well maybe 10 years ago, but with the current JVMs GC is transparent and for most people not even noticeable.

      Agreed java has memory bloat but the biggest problem i have is that not that the GC has "pause times" but that the GC is not aggressive enough in freeing up memory.

  41. analogy by dark+grep · · Score: 1

    a-choo - excuse me. So a Toyota Camry is the best all-round performer of vehicles on the road today, But if you want super performance, buy a Ferrari, and if you want to haul freight, buy a Mac truck. Really? Wow. Could a more pointless generalization be possibly made about programming languages? What it really points to is that Google have now totally lost the plot in their love affair of their own cleverness. Hello Borg Mk II

  42. 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.

    1. Re:Also by nitehawk214 · · Score: 1

      It often turns out programmers are not as good at the assembly as they might think.

      Make it possible for programmers to write programs in assembly, and you will find that programmers can not write in assembly.

      --
      I'm a good cook. I'm a fantastic eater. - Steven Brust
    2. Re:Also by Anonymous Coward · · Score: 0

      but the "I can do better than a compiler," attitude usually has no basis in reality.

      It would seem you've never heard the tale of Mel:

      http://www.pbm.com/~lindahl/mel.html

    3. Re:Also by LWATCDR · · Score: 1

      Even if they are you should always look at optimizing the algorithm first. Once you have taken that as far as you can find the critical areas and then try to write small very optimized functions to improve those.
      Using the required car metaphor. A good driver can out stop anti-lock brakes in tests. When someone slams on their brakes in front of you on a slick road things are different. Writing really optimized assembly code is so intense and demanding that it is a very rare person that can do it reliably for long periods of time. It is better to save that effort for small critical sections.

      --
      See my blog http://ilovecookes.blogspot.com/ for light hearted technical information.
    4. Re:Also by Anonymous Coward · · Score: 0

      I'm by no means an Assembly master, but I have already gotten huge (about 8-16x) speedups by adding a tiny bit of inline assembly to a simple and obvious inner loop. SIMD tends to do that, and auto-vectorization is mostly myth.

      There are also some programs, where there are really huge amounts of Assembly, which actually help performance. Take a look at x264 for example.

    5. Re:Also by m50d · · Score: 1

      C++, of course, is something you can quite easily write a very large program in, or operating system for that matter.

      The current security records of major operating systems suggest otherwise. I don't think C++ is a sensible choice for large-scale projects, because the implications of a single mistake anywhere in the code can be enormous.

      --
      I am trolling
    6. Re:Also by Anonymous Coward · · Score: 0

      Unless you're Steve Gibson, of course.

    7. Re:Also by ImprovOmega · · Score: 1

      Where it really shines is making use of assembly instructions that the compiler doesn't know about. Like introducing SSE/MMX into digital processing routines. Of course, this is also just inline assembly in the midst of everything else, but for those small sections that eat like 95% of the execution time, it can make a lot of sense to introduce some clever parallel processing, cache hints, etc.

    8. Re:Also by darronb · · Score: 1

      Actually, compilers are NOT nearly as good at optimizing things as people seem to think. They have a whole lot of individually very clever optimizations, but it is pretty easy to beat them. You can restructure and refactor code freely, compilers must be reasonably true to the code you wrote.

      The real problem is that perhaps even a majority of programmers are nearly incompetent, and most of the remainder aren't all that good at it.

    9. Re:Also by Anonymous Coward · · Score: 0

      No. There is no way C++ can be faster than assembly given this little trick, used on an AVR:

      For sensor readings, averaging is a nice way of getting better data from a noisy sensor. If you take 256 16-bit samples and add them together you have a 24-bit number. To divide that by 256 - averaging - You just switch registers, dropping the low byte and using for your result the two high byte registers. It's a zero-cycle divide.

      Zero. I'd like to see your optimizers top that... Hand-tuned assembler will always be faster, if you know what you're doing.

        AC

    10. Re:Also by jomama717 · · Score: 1

      There is a chapter in Michael Abrash's Graphics Programming Blackbook called "Don't be a Compiler Johnny" that supports your statement.

      --
      while [ 1 ]; do echo -n -e "\xe2\x95\xb$((($RANDOM&1)+1))"; done
    11. Re:Also by ceoyoyo · · Score: 1

      It depends what you're doing. Embedded or GPU programs are usually small and performance intensive. Someone who's good at writing assembly can usually do better than the C or C-like languages people use to program them these days.

      Of course, anyone who writes a big application in assembly today is an idiot. A lot of people would say that about someone who writes a big application in C too. But the little bits that do most of the work can still use some low level love. That's why one of my most important criteria for a language these days is how easy it is to bridge to stuff written in other languages.

    12. Re:Also by Anonymous Coward · · Score: 0

      Actually nowadays, it's gotten easier to beat the compiler in numerical stuff. The last few generations of CPUs have put a lot of emphasis on vector ops, which compilers have a hard time producing. Ironically, in part because C/C++ are such unsafe languages (e.g. pointer aliasing), the compiler can't prove the code can be safely vectorized. My understanding is easy vectorization is one reason Fortran tends to be faster than C/C++.

  43. blah blah blah so much comment text by Drake_Casanova · · Score: 1

    The closer to writing in pure binary the more efficient your code potential is. Im sorry for the guys who invested so much time mastering Java and still have hopes to become world renowned programmers.It is no wonder why embedded developers are in such high demand.

    1. Re:blah blah blah so much comment text by equex · · Score: 1

      But....but... the compiler...it will produce better code than the best assembly nerd.. ? Now is this true or is it something said by butthurt OOP programmers?

      --
      Can I light a sig ?
    2. Re:blah blah blah so much comment text by fyngyrz · · Score: 1

      That would very much depend on the compiler. I just looked at the code output of the GCC compiler when fed objective C (very close to c), and trust me, the code was HORRIBLE. GCC is a pretty modern compiler, as things go, and there's one case where code generator optimization -- and I use the term extremely freely here -- was apparently not even attempted, or if attempted, is a mad fail.

      I'm sure, speaking as a very experienced asm programmer, that some compiler, somewhere, someday, could outcode me on some given architecture (and more likely on architectures that are slovenly, like Intel's usual weirdness), but I think it's worth reporting that I've not yet encountered said compiler.

      --
      I've fallen off your lawn, and I can't get up.
  44. No INTERCAL? by Ardeaem · · Score: 1

    What, no INTERCAL? It could have blown away the competition; it has "COME FROM"!

    1. Re:No INTERCAL? by shutdown+-p+now · · Score: 1

      I'm pretty sure that Nil programming language would roundly spank even C++ - much less Java or Go - on any of the metrics considered; especially memory usage and execution time!

  45. C++ could have been a lot faster by xquark · · Score: 1

    The paper doesn't talk about using:

    1. Custom allocators (stack and pool based)

    2. Move semantics

    3. Modern C++ idioms such as expression templates

    I believe if these were used, the performance would have even better and left the rest "truly" in the dust...

    --
    Arash Partow's Philosophy: Be a person who knows what they don't know, and not a person who doesn't know.
    1. Re:C++ could have been a lot faster by 21mhz · · Score: 1

      I believe if these were used, the performance would have even better and left the rest "truly" in the dust...

      Yes, it would do justice for the 10 people who can do it correctly. And used as an excuse by hordes of self-proclaimed C++ experts to write more bad, convoluted, poorly performing code.

      --
      My exception safety is -fno-exceptions.
    2. Re:C++ could have been a lot faster by shutdown+-p+now · · Score: 1

      Well, they do use STL containers in their code. A particular implementation would normally use move semantics internally for those where available.

      I'm not sure what you mean by "expression templates" - template metaprogramming? But how would that help here, since the computation that has to be performed is not compile-time?

    3. Re:C++ could have been a lot faster by xquark · · Score: 1

      Using stl containers is not the issue, most people use stl containers in their default mode. My point was to use custom allocators with such containers. Specifically stack based ones if the container will only exists within a function call etc. perhaps even used EA-STL

      As for expression templates, its not all about compile time computations, most often than not its a mechanism to explicitly specify how a computation should be done - this happens a lot in linear-algebra based implementation - check out the various uses in Blitz++, Boost Fusion, Boost Graph etc..

      Also note move semantics weren't used with the compiler/library mentioned in the paper.

      In short if the above were done/used the difference would have been MUCH greater.

      --
      Arash Partow's Philosophy: Be a person who knows what they don't know, and not a person who doesn't know.
  46. Oh really? by CountBrass · · Score: 1

    Please show me how to implement Macros -proper Lisp-style macros- in C or C++ so that they are available in standard C (or C++).

    Thanks.

    --
    Bad analogies are like waxing a monkey with a rainbow.
    1. Re:Oh really? by headkase · · Score: 1

      I should have elaborated on my comment a bit. I never said it would be syntactically beautiful: just that you could do it.

      For example, back in the Amiga days I implemented a Object-Orientated GUI in AMOS Basic. That was a procedural language. It ended up having lots of stub functions to handle the object part of the implementation and as the language didn't allow variable numbers of arguments to procedures sometimes you had to call the stubs with null values for parameters that weren't needed. Internally, I had no access to direct memory allocation so I had some general purpose arrays. Like GUI(30,10) which was a maximum of 30 objects with a maximum of 10 attributes. In parallel to that array I would use a string array: GUI$(30) for the same number of objects for things like text fields. Then accessing - through the stub functions - objects were given the first number - the index or "object" - and a specified attribute index and the stub functions were basically methods on the object. The Basic interpreter didn't enforce any of the object-orientation: that was all up to me with programming-style and if you didn't follow the style you broke it.

      Now that example was not elegant at all but I successfully added functionality that was outside the scope of the language. Ugly as sin though.

      --
      Shh.
    2. Re:Oh really? by Anonymous Coward · · Score: 1

      Go download the source for a Lisp interpreter written in C or C++.

  47. Next research paper comming by Anonymous Coward · · Score: 0

    Waiting for the same performance test between french, english, german and spanish. God, that will be interesting! And almost as useful.

  48. Excuse me by aikbix · · Score: 1

    Is that a challenge Google?

  49. BS Title by gweihir · · Score: 1

    The competition was Java, Scala and Go. Quite a limited set and definitely missing C for one. And unlike C++ optimization, optimizing C is something you can do without understanding details of the compiler. So I will definitely stay with C for everything that has high performance needs, even if I have to do the OO aspect myself.

    --
    Most ACs are not even worth the keystrokes to insult them. Be generically insulted by this and ignored otherwise.
    1. Re:BS Title by shutdown+-p+now · · Score: 1

      C89 can be mapped to C++ very easily - it's almost a direct mapping with a few minor corner cases. So the argument for C as something "easier to understand" is somewhat meaningless - for those cases where you need in in C++, you can always reduce the used subset of a language to near-equivalent of C for that particular chunk of code; and still use all the nifty stuff such as objects and templates elsewhere.

  50. Read the Abstract by Anonymous Coward · · Score: 0

    'While that effort is an anecdotal comparison only[...]' .. Come on. The title is about loop recognition, not about finding the fastest language on the market. There's no such thing. Depends on what your objectives are and the application type.

  51. Is that a joke? by Anonymous Coward · · Score: 0

    The paper compares an heavily optimised version with a version in another language with no optimisation?

  52. Effort needed to get reasonable speed by r6144 · · Score: 1

    This is what matters for me. I want my program to have acceptable speed just by writing it in the most straightforward way. Squeezing out the last bit of performance isn't usually necessary, but 10x slower is also unacceptable. Many people defend slow languages by saying that premature optimization is the root of all evil, but in C/C++, you simply don't need to do ugly premature optimization in most cases, since the program often runs fast enough as long as all best practices are followed.

    C++ seems to be useful in most cases as long as all developers know it well (using correct data structures, not copying large objects around unnecessarily, etc.), including important libraries in STL and Boost.

    C is also good with the right libraries such as glib. It is more verbose than C++ and manually freeing all the memory can take a bit of developer time, but it is also easier to learn.

    Fortran 90 is even easier, but is only suitable for numerical programs without complicated data structures. Java is also easier and fast enough, and may be a good choice for non-numerical work (numerical programming is still a bit awkward).

    Scripting languages are, for the most part, still too slow for non-scripting work. Sure, a program in these languages can be made faster by writing some speed-critical parts in C, or by writing the program carefully so that my particular implementation can optimize it well, but this will usually take more effort and make the program harder to maintain.

  53. bad benchmark by t2t10 · · Score: 1

    The benchmark imposes the restriction of using "idiomatic constructs". But that's just what you wouldn't do if you had to optimize a performance critical section by hand.

    Nevertheless, for deciding among those for languages, the conclusions are probably still reasonable. The verbiage before just serves as an alibi.

    What the paper really says is "we don't want to use Go"; there is probably pressure to do just that inside Google.

  54. Says who our CPUs aren't getting faster? by Sycraft-fu · · Score: 1

    Seems to me they are. For one, their MHz are pushing up. Not by leaps and bounds, but they keep improving. Take a look at the last three generations of mid-range quad core Intel chips ($300ish):

    --Sandy Bridge (current) goes from 3.4GHz to 3.8GHz depending on core load (meaning it changes speed dynamically).

    --Lynnfield goes from 2.93GHz to 3.5GHz depending on core load.

    --Yorkfield 2.67GHz, no boosting.

    Yorkfield came out in March of 2008, Sandy Bridge in January of 2011. So in in about 3 years base clock rate has gone up 700MHz and beak clock rate over a GHz.

    Now that aside, the CPUs are getting much more efficient per clock. You find that each generation has significant per clock gains over the last one. Same code, same MHz, faster execution.

    Then of course there's new instructions. AVX in particular really boost Sandy Bridge's floating point speed.

    Add it up, they've increased in speed a lot.

    I agree that threading is important, as I noted all this is on quad core processors, but the idea that you can't do threaded code in C++ is silly. The most simple demonstration against that is all the PC games out there. Nearly all of them are done in C++ (Visual C++ to be specific) and these days they are all multi-threaded. For more intense threading in C++ apps, have a look at audio software and plugins.

    If your products are all ones where speed is not an issue, and there are plenty that are not, and where the overhead of Java (not so much things lime memory, more like administration in that Java wants to update all the time and you have to have it installed before you app works) are ok then wonderful. However there are a lot of applications out there where performance matters and it still seems to be that languages that generate native code, like C++, do a better job.

    1. 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.

    2. Re:Says who our CPUs aren't getting faster? by w_dragon · · Score: 1

      Go take a look at boost and ace and tell me threading and locking is hard. Just because Java has all the libraries distributed with the platform doesn't mean the same things aren't available for C++

    3. Re:Says who our CPUs aren't getting faster? by Splab · · Score: 0

      What is it with you people and reading things that isn't there?

      I don't claim threading to be hard in C++, I claim Java threading is vastly easier - see the difference? Also, if you know any C++ programmers you'd know that boost et. al. are almost never ever allowed into any big product.

    4. Re:Says who our CPUs aren't getting faster? by Anonymous Coward · · Score: 0

      The computer I'm writing this on has a 3GHz Pentium 4. I bought it in 2004 and it wasn't the fastest then; I could have paid another $500 for 3.4GHz. Yes, processors are getting faster, but clock speeds are not increasingly significantly.

    5. Re:Says who our CPUs aren't getting faster? by gbjbaanb · · Score: 1

      but they're not getting faster.

      I used to have a box with a 2x 3Ghz CPU. Now I have a box with a single 1.2 Ghz CPU.

      the box has gotten quite a bit smaller too, which is handy as the old PC wouldn't fit in my pocket, or make phone calls.

      The Microsoft approach of expecting faster hardward to make up for software inefficiencies no longer applies. We all need to remember that and code better, rather than trying to make development simple enough that your job can be outsourced :)

    6. Re:Says who our CPUs aren't getting faster? by Asmodae · · Score: 1

      The future is threaded applications - if you can't thread, go find yourself a nice FPGA.

      Whoa whoa whoa there. How in the world is someone who can't handle multiple concurrent processes (like threads) going to do anything coherent with hardware where everything is concurrent?

    7. Re:Says who our CPUs aren't getting faster? by Puff_Of_Hot_Air · · Score: 1

      Also, if you know any C++ programmers you'd know that boost et. al. are almost never ever allowed into any big product.

      Say what? BOOST usage is controlled in large projects; as in most projects will pick and choose relevant parts of BOOST (usually through some formal or informal process), and forbid others. It's a ridiculous assertion to suggest that most "big" products would not use BOOST, but rather re-invent the wheel. To suggest that BOOST is not used by the majority of professional C++ developers is pure disinformation. Your ignorance is continuing to show.

  55. C is faster than Fortran by G3ckoG33k · · Score: 1

    Even if I prefer Fortran to C due to the ease of handling matrices, I haven't seen any case where Fortran is faster than C. Therefore "when the going get tough FORTRAN get going" cannot be due to speed. Or, any links to benchmarks to back it?

    1. Re:C is faster than Fortran by paulatz · · Score: 1

      Unfortunately my dog ate the benchmarks when I was about to post them. I'll send you a dietary supplement of humour instead.

      --
      this post contain no useful information, no need to mod it down
  56. 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 Anonymous Coward · · Score: 0

      I call bullshit. What you're saying is true only if you use the strictfp keyword, and I doubt that it would be used in any performance benchmark.

    4. 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.

    5. Re:I don't know about that by Anonymous Coward · · Score: 0

      >why Fortran beats C ... when it comes to numerical computation.
      Nope.avi

      Use the 'new' C99 'restrict' keyword on your float* and you too can have all of the FORTRAN style prefetched optimizations

      Just because most programmers don't know about a feature doesn't mean it doesn't exist.

    6. 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!
    7. 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!
    8. Re:I don't know about that by Anonymous Coward · · Score: 1

      ALL C++ numerical types have guaranteed minimums. long is guaranteed to be at least 32-bits. long long is guaranteed to be at least 64-bits. C++ is always portable if you follow the guarantees.

    9. Re:I don't know about that by timeOday · · Score: 1

      It was generating millions of unnecessary objects per second, and the runtime was swamped by GC overhead.

      I have a beef with Java's inefficiency with repetitive memory allocations for temporary objects. Sure, you could just allocate some data structures up front and re-use them for everything. That amounts to a reversion back to FORTRAN-style programming, where dynamic memory allocation of any sort is a novelty and the structure of the code is dictated by what will run efficiently. What's the point of even calling this Java, when you're just coding around the features it offers because they're too slow?

      With C++, you can allocate those objects on the stack very efficiently, with no more scope than necessary.

    10. Re:I don't know about that by tixxit · · Score: 1

      This argument was only valid before Java 6. Before Java 6, non-strictfp calculations were still treated as strict. In Java 6 and beyond, non-strictfp floating point calculations are no longer forced to be strict and Java's math benchmarks got significantly better.

    11. Re:I don't know about that by Anonymous Coward · · Score: 0

      Though the focus of the paper wasn't supposed to be Java vs C++ that seems to be where most of the comments are geared.

      Wonder if this has anything to do with the Oracle v Google lawsuit over Java/Android.

    12. Re:I don't know about that by semi-extrinsic · · Score: 1

      Exactly, Fortran is faster. I know so, by a factor of 2-3x at least. So why is this guy claiming C++ is the fastest??

      --
      for i in `facebook friends "=bday" 2>/dev/null | cut -d " " -f 3-`; do facebook wallpost $i "Happy birthday!"; done
    13. Re:I don't know about that by bored · · Score: 1

      Fortran beats C or C++ when it comes to numerical computation.

      C, yes. C++, is basically a tie when template libraries are used. Over the past ~5 years a number of C++ libraries have become available that are roughly equivalent (some faster, some slower depending on application) to Fortan performance.

    14. Re:I don't know about that by Darinbob · · Score: 1

      "C" floats? Surely you mean IEEE 754? And not all compilers are required to follow IEEE standards.

    15. Re:I don't know about that by Prune · · Score: 1

      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.

      WTF? I was going to mark your comment overrated as you even bother to RTFA, but I thought it better to clear up the disinformation you're spreading given your pro-Java zealousness. Even in the original comparison of the unoptimized versions, C++ wins by a large margin over the Java test with the best GC choice for this case (23 s vs 89 s). To add insult to injury, even Scala smoked Java.

      Another point to make is that the quote in the /. summary from the article discussing the paper, that "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" is misleading, to say the least--the paper doesn't make such a claim, which is yet another example of why it's best to stick to quoting the primary sources whenever possible. I was almost excited, looking forward to reading about some hardcore C++ optimizations, and I was quite disappointed, as there was hardly anything in there that an intermediate programmer shouldn't be aware of.

      --
      "Politicians and diapers must be changed often, and for the same reason."
    16. Re:I don't know about that by Citizen+of+Earth · · Score: 1

      People write video codecs in C/C++ instead of Java because Java is slower. Deal with it.

    17. Re:I don't know about that by Anonymous Coward · · Score: 0

      Changes which, I might add, are still far easier for the average Java peon-on-the-street to understand than the C++ equivalents.

      Er, right, but they're near identical to similar performance issues in C++ programs. Syntax different? Sure. Understanding that allocation/deallocation of billions of integers a second might have an impact on performance? Same. Ease of figuring out that this allocation/deallocation is even happening? FAR easier in C++, where you explicitly call new()/destroy() on your objects, and malloc()/free() on your pointers.

      I could continue: use of HashMap where int would suffice - no different in C++, there are only differences in the syntactic sugar. LinkedList vs. ArrayDeque.. I don't even know what an ArrayDeque is, but this is the same issue as the HashMap, really - your data is being stored in a form more complex than is warranted, and it's pushing other stuff out of processor cache, slowing your code down.

      Everyone who wants to write anything even remotely performance oriented should spend a few months learning to code efficiently in C (or assembler.) Knowing how the processor actually treats your data (hint: no machine code for a processor that currently exists has instructions that do anything at all with "objects") makes a world of difference when looking for things that might slow it down. The other half is algorithms. Learn what O(1), O(n), O(2n), and O(n^2) mean, and learn to visualize which pattern you're using in your own code. ( O(log n) and variations in practice pretty much show up only in sort algorithms, so unless you're writing an I/O elevator or something that one won't come up too often. And I hope you're not writing an I/O elevator in Java.)

    18. Re:I don't know about that by ultranova · · Score: 1

      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

      Because Java has random pauses due to garbage collection, which are bad for games or audio software. Also, garbage collection interacts badly with memory-hungry programs which might hit the swap.

      Also, most operating systems and their API layers are written in C or C++, so it's easiest to interact with them with those. Use Java, and you need to do things like use "finalize()" to ensure OS resources are properly disposed of, or risk resource leakage. However, finalizers are called by the garbage collectors, which is unpredictable. It's two design philosophies colliding, and becomes a mess really soon as you try to patch over the resulting ill fit to keep your abstractions from leaking.

      or why Java linpack pulls like 750Mflops on a system where native compiled (from C) Linpack gets 41Gflops.

      According to Wikipedia, Linpack is written in Fortran. And Java can (and in modernJVMs is) compiled to native code. So what are you comparing to what?

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    19. Re:I don't know about that by ultranova · · Score: 1

      People write video codecs in C/C++ instead of Java because Java is slower.

      No, they write video codecs in C/C++ because it makes it easier to interface with video players that are also written in C/C++. And video players are written in C/C++ because it makes it easier to interface with video codecs which are written in C/C++.

      Deal with it.

      With what?

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

    20. Re:I don't know about that by shutdown+-p+now · · Score: 1

      Overly strict guarantees for floats haven't been a problem since Java pretty much since "strictfp" keyword has been introduced (in, what, Java 1.2?). The default behavior is non-strict now, which permits Java to do all the same optimizations as (portable) C with respect to floats.

    21. Re:I don't know about that by shutdown+-p+now · · Score: 1

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

      Except they weren't. From the table:

      (benchmark - time in sec)
      C++ Opt - 23
      Java 32-bit SPEC GC - 89

      Note that "C++ Opt" doesn't refer to the hand-optimized C++ version - that is called "C++ Pro", but is not in the table because they can't publish the source (it depends on some of their internal libs). It rather refers to "naive" C++ version compiled with optimizations enabled; there's also "C++ Dbg" in the same table, which is the exact same program compiled with optimizations disabled.

      And what we see here is that "naive" C++ is almost 4x as fast as "naive" Java - and note that this 89s result for Java is using a hand-tuned GC flag combination.

      One other thing missing in the comparison is that "naive" C++ code is using std::map, which is a balanced binary tree (typically red-black) key-sorted map, whereas Java was using a HashMap. So C++ version was actually using a data type that is supposed to be slower (except on pathological inputs).

      By the way, I think that I wouldn't use the word "naive" here, but rather "idiomatic" - in other words, how people actually write programs in this language when they're not doing so for perf benchmarks)

    22. Re:I don't know about that by Daniel+Phillips · · Score: 1

      Java has random pauses due to garbage collection, which are bad for games or audio software. Also, garbage collection interacts badly with memory-hungry programs which might hit the swap.

      And don't forget JIT compiling which causes massive lag on startup or when the application hits a previously unused code path. Aso consumes large amounts of memory.

      --
      Have you got your LWN subscription yet?
    23. Re:I don't know about that by ceoyoyo · · Score: 1

      Sigh. Can we just agree that both Java and C++ are the wrong choice if you want performance? Obviously you should write hand tuned assembler like a real programmer.

    24. Re:I don't know about that by dave87656 · · Score: 1

      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!

      I think what you will hear is that in many cases Java is "around" as fast as C++ when you don't have the time to tune a C++ app. If you tune a C++ app, it is almost always faster, but you have to know what you are doing. My background was C++ and other 3G languages for most of my career, but the last 11 have been in Java. Java does a pretty good job given that it's a generalized managed language, but I love the crispness of a C++/Gtk app.

    25. Re:I don't know about that by Anonymous Coward · · Score: 0

      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).

      Yeah, right! That's the only reason why C++ is faster than Java! Are you kidding me or just yourself?

    26. Re:I don't know about that by Anonymous Coward · · Score: 0

      The fact of the matter, and the most important factor in choosing a language for performance-oriented programming is that you actually can optimize a C++ program to "within and inch of its life" and use nothing but C++ for that. Any other language that gives you this feature is (I believe) much harder to program in than C++.

      If you can't accept some complexity (which is a soft limit) in order to gain performance (which in some applications is a hard limit,) then either you are a wuss (;-)) or you have that luxury. I don't.

    27. Re:I don't know about that by rjstanford · · Score: 1

      If you believe that a 3.8x difference between code that's been written by an expert, vs. code written by a novice and slightly cleaned up, presented in a paper that itself warns that its findings should only be considered useful at the order-of-magnitude level is a small one, then we read a different paper. If you read the pullquote you responded to, you would see that a couple of minor changes brought the performance directly more in line (a 2-3x improvement).

      The fastest, unpublished, version of the C++ code uses extensive Google proprietary libraries. No such effort has been made on the Java version, indeed it had received substantially less tuning than the basic C++ one provided with the paper.

      --
      You're special forces then? That's great! I just love your olympics!
    28. Re:I don't know about that by jgrahn · · Score: 1

      Another point to make is that the quote in the /. summary from the article discussing the paper, that "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" is misleading, to say the least--the paper doesn't make such a claim, which is yet another example of why it's best to stick to quoting the primary sources whenever possible.

      It's a direct quote from VII Conclusions. Not that I see what it refers to -- the tunings the paper describes seem to be (a) bloopers in the original code, such as using std::map instead of faster and just as maintainable alternatives; (b) pretty obvious things, such as writing a custom container to replace the general std::set (TinySet). (c) algorithm tunings, not really related to C++.

  57. objc by fyngyrz · · Score: 1

    I haven't used Apple's new compiler, but under Leopard (10.5), using GCC, the actual machine code that is produced for objective c is *awful*. Constantly re-using the same registers, putting them away, bringing them back... it's as if the compiler uses a one-type-of-each-register model. Speaking as an assembly programmer, for any particular procedure that I looked at, I could have *trivially* whipped GCC's ass back into the stone age for execution efficiency.

    Apple says the new compiler produces better code, and all I have to say at this point is that shouldn't have been difficult to do, because obj-c -> gcc sucks ass.

    --
    I've fallen off your lawn, and I can't get up.
    1. Re:objc by TheRaven64 · · Score: 1

      I don't work on Apple's implementation of Objective-C, or on GCC, so I can't comment on this. LLVM has a few register allocators, used depending on your requirements (speed of compilation vs speed of execution). The register allocator is exactly the same for C, C++ and Objective-C with both GCC and LLVM though (register allocation is in the last phase in code generation, long after source-language details have been lowered), so if you see this then it won't be specific to Objective-C.

      --
      I am TheRaven on Soylent News
  58. You're misunderstanding the argument by Xest · · Score: 1

    No they're not, they just better understand the argument than you do apparently, and Google's conclusion doesn't disagree with them.

    I think everyone agrees C++ can theoretically perform faster, but as Google notes you need to perform a lot of optimisations by hand which requires a lot of time, and a high degree of skill to perform.

    The argument for Java is that it performs as well as C++ when you either do not have the time to do these optimisations, or do not have the skill to do these optimisations. There is a further argument that in this day and age there is no point doing such optimisations because the performance edge is small enough to be not worth investing the time in.

    The fundamental point is that an extremely skilled developer, with no deadlines, will always be able to produce better performing code in C++ than Java, but:

    - Time is money
    - Skills cost money
    - The code may be harder to read and maintain due to optimisation
    - The software will be inherently more prone to developer errors that can lead to security vulnerabilities

    So in the real world C++'s performance advantages are more often than not, irrelevant. That is, the real world doesn't really care about performance penis waving C++ developers 99.99% of the time, because they'd rather have code that's portable, easily maintainable, has a smaller potential attack area, and is developed in a cost effective manner. It is these real world factors that give Java the edge, and under these real life factors that C++ struggles to compete. That is why Java, and other languages like C# and .NET have eaten massively into C++'s marketshare in the last decade.

    The arguments implying C++ is the one true language are produced only by those lifelong code monkeys who never got passed that role because they simply never understood the practical or business side of things, and without a doubt whilst they can write great code that performs well, there will be inherent disadvantages- their code will over time simply by nature of humans inability to be 100% consistent in avoiding mistakes be more prone to security vulnerabilities, will be less maintainable, and will cost more to develop.

    It's really about the best tool for getting the job done without worrying about some performance gain only noticable to a user if they see the sub-second comparison metrics listed for them, and I'm glad to see others point that out too- knowing when to and not to use a certain tool is the sign of a great developer, not dismissing dissenting opinions as vocal idiots without apparently even understanding the argument they make.

    1. Re:You're misunderstanding the argument by gbjbaanb · · Score: 1

      The arguments implying C++ is the one true language are produced only by those lifelong code monkeys

      spoken like a true businessman. Let me know how happy you'll be when your job gets sent to India because coding has become so simple the cheapest of the unskilled can do it.

      Those guys you libel are actually code professionals, not monkeys. you'll find they want to do a good job, not an adequate or substandard one just because your PHB is counting beans. You'll see why the performance issues are an issue if you ever spoke to your users and saw them struggling with the enterprise Java software that is way slower than the benchmark figures say it should be.

      I've never really seen a decent Java application that didn't suck up RAM, perform sluggishly, or scale dreadfully. Hudson did make me question my thought that Java was a total pile of bull, but even then, I've seen the same kind of app written in PHP or Ruby or Perl that performs the same web-UI task just as well. That makes me think that you're right... the right tool for the job, and that's never going to be Java. If I want fast code, it'll be C/C++. If I want quick development, it'll be a script language. Java falls into the "neither" camp. So I wonder why you still use it if you stand by your arguments :)

    2. Re:You're misunderstanding the argument by brainzach · · Score: 1

      p>The argument for Java is that it performs as well as C++ when you either do not have the time to do these optimisations, or do not have the skill to do these optimisations. There is a further argument that in this day and age there is no point doing such optimisations because the performance edge is small enough to be not worth investing the time in.

      Most of the performance bottlenecks occur in a small section of the code base. A smart developer would spend their time optimizing those section that produce the best bang for the buck.

      I agree that Java and C# is better for developing most applications but C++ has its niche. If your application requires serious number crunching then C++ is the way to go.

    3. Re:You're misunderstanding the argument by cecille · · Score: 1

      It seems strange to assume that every person ("code monkey") who still writes code late into their career is doing so because he/she "simply never understood the practical or business side of things". There are plenty of developers who understand the business side of things, but just don't want to go into the business side of management. In our company, and I think probably in a lot of others as well, there are two different paths up the food chain. You can either code for a while and then try to get into management with the goal of being a project/product manager and up, dealing with issues like customers and business strategy, or you can work your way up the other side try to become an architect, where you're working on more technical issues. Either way, you end up basically managing people, but as an architect you're still writing code well into your career.

      --
      ...no two people are not on fire.
    4. Re:You're misunderstanding the argument by bored · · Score: 1

      I've never really seen a decent Java application that didn't suck up RAM, perform sluggishly, or scale dreadfully. Hudson did make me question my thought that Java was a total pile of bull, but even then, I've seen the same kind of app written in PHP or Ruby or Perl that performs the same web-UI task just as well. That makes me think that you're right... the right tool for the job, and that's never going to be Java. If I want fast code, it'll be C/C++. If I want quick development, it'll be a script language. Java falls into the "neither" camp. So I wonder why you still use it if you stand by your arguments :)

      Exactly, that has been my attitude, when Sun started pushing java for back-end processing rather than heavyweight UI's. The idea of a crossplatform UI tool was pretty intriguing in the mid 90's. But the results (ugly, slow, apps that didn't look like everything else on the system) were abysmal. Then they started pushing it for backend processing and I was like WTF? Whats the point of cross platform in that case? Its neither a fast IO language, didn't scale worth a crap (its better now) due to library problems, and the GC tended to consume 2x-5x the memory for similar tasks. Plus any kind of hardware interaction pretty much means dealing with the OS/ioctls/etc. For that you really want a language with native C bindings.

      In the end C++ makes a pretty good "engine" language, and there are far better UI or processing languages.

    5. Re:You're misunderstanding the argument by shutdown+-p+now · · Score: 1

      but as Google notes you need to perform a lot of optimisations by hand which requires a lot of time, and a high degree of skill to perform.

      That's not what they say, actually. They say that C++ can be made significantly faster than everything else, and that requires a lot of hand optimizations. Nonetheless, from the tables in the paper, it is clear that unoptimized, straightforward C++ version is still faster than "expert-optimized" Java version.

      This doesn't really change your assertion that

      So in the real world C++'s performance advantages are more often than not, irrelevant

      because C++, even when written in a direct and straightforward way, is still more complicated than Java/C#. That said, there are many different areas in real world, and in quite a few of them (even in desktop apps), C++ perf advantages do matter.

      To give one particular example from personal experience: I was working on a C# WinForms application, which needed to manipulate an HTML document loaded into a hosted IE control. It turned out that there was a major perf problem there because it required a lot of calls that went from managed app code into native IE code via COM interop (basically, imagine walking over a DOM tree of a large HTML document, performing something on every node) - and the overhead for a single such call (type conversion esp. for strings, RCW/CCW creation etc), while not significant on its own, was large enough in aggregate that it became a major perf issue. The answer was to rewrite that entire part as a native C++ DLL, into which C# did a single call through the interop boundary, passing all input data in a struct + the pointer to IE object, and receiving a struct filled with results.

    6. Re:You're misunderstanding the argument by Xest · · Score: 1

      "spoken like a true businessman. Let me know how happy you'll be when your job gets sent to India because coding has become so simple the cheapest of the unskilled can do it."

      Oh my god, no, you called me a businessman! I'm deeply offended! No seriously, if the biggest insult you can come up with is that I'm basically someone who realises the reality of business then it shows you don't really have a point. More importantly, my job wont get sent to India precisely because I'm smart enough to stay ahead of the curve and not limit myself to one single language falsely believing it's the one, the saviour, the only language you would ever need.

      "Those guys you libel are actually code professionals"

      Monkeys, professionals, whatever, if they truly believe C++ is the be all and end all and the key for all development then they're shit whatever you prefer to call them.

      "You'll see why the performance issues are an issue if you ever spoke to your users and saw them struggling"

      Right, because I don't do that or anything. No seriously, it's another trait of a good developer- interacting with your users, and this is what's so utterly ironic about this comment- developers who stick to C++ for everything tend to be the same folks who don't really leave their desk to realise that their performance boosts in C++ haven't actually achieved any real world advantage over just getting the job done quicker, with greater stability, and greater security in another language.

      "I've never really seen a decent Java application that didn't suck up RAM..."

      Ah, you're one of those, those that doesn't understand that maximising RAM usage when there is free memory is a good thing because it means greater performance. You think it's good to just have lots of memory lying around unused not doing anything- tell me, why do you think you have RAM in your computer? Just for bragging rights about the amount of RAM you have or something?

      "..., perform sluggishly, or scale dreadfully."

      Right, I guess you never heard of eBay or Google, the former which uses Java pretty exclusively, the latter of much of whoms backend code is written in Java. I guess eBay and Google just never managed to scale well. Vuze is a decent example of a desktop application written in Java which performs just fine.

      "but even then, I've seen the same kind of app written in PHP or Ruby or Perl that performs the same web-UI task just as well. That makes me think that you're right... the right tool for the job, and that's never going to be Java."

      Which is quite amusing in the context of your previous comment about Java failing to scale- tell me, what language were they using at Facebook because it failed to scale? Oh yes, PHP. What language was Twitter using when it had an abundance of scalability issues in it's early days? Ah yes, RoR. If there's one thing Java does incredibly well, it's scale, and that's where it's really in it's prime- highly scalable server side applications.

      The issue with script languages is that they truly are slow, if you don't understand the difference between such languages and JIT'd languages like Java and the .NET languages then there's your problem- you don't even understand the fundamentals of what you're trying to argue. You don't even seem aware in the slightest of numerous examples of managed code doing just fine, whether it's pretty muche very smartphone on the market today, or sites and services you probably used daily without even realising it from Google, eBay and Smartphones, to banking ATMs/sites, to stock control and checkout systems. All these things are often underpinned by Java. It's the single most used language in enterprise and has been for about the last 5 - 10 years with good reason.

      I don't pretend there aren't a lot of skilled C++ developers out there, nor do I pretend Java is some be all and end all language. But in the world as it is now, Java is one of the better choices for much software development, just as C++ was 15 years ago, and I suspect

    7. Re:You're misunderstanding the argument by gbjbaanb · · Score: 1

      hehe. Still, I think you do miss my point somewhat.

      1. maximising free ram usage is a fallacy. If you have the entire system to yourself, then it is fine, suck up as much as possible. However, our systems do not have that luxury - I have several apps running, and if each one is written to use RAM like its going out of fashion, they'll only end up starving each other for resources. the GC will be kicking in much more often, or worse case - you'll be swapping. I understand the theory, but the practice is quite different. There's another aspect to this that people forget - RAM is not a free resource, it costs quite a bit to copy that data in and out, which we see with today's monumentally slow startup times.

      Performance. I know script languages are crap, but when you have a situation where a slow tool is acceptable, you'd be right to use it. UI is a slow task - human reactions are dreadful in computer terms, so if the UI can be written in script and it performs fast enough, then you'd be choosing the right tool to write your UIs with it as hopefully development time would be insignificant.

      Java does not scale, absolutely not, and enterprise java is really a synonym for 'horrible crap' (think Siebel, or similar examples). The examples you give might use some java, but ebay and Google use c/c++ code for their 'good stuff' even if they give them a 'user friendly' java SDK for devs to work with. I'll check out Vuze and see if its any good, but so far the best java app I've seen is still Hudson with its HTML-based UI.

      As it is, I am a very competent developer. Maybe that's why I can code stuff up in C++ and not have to fall back on the 'easy' stuff like Java and C#. As it is, I think I do more C# now but its not fun.. the Ruby on Rails stuff I'm getting into though.. now that is fun.

    8. Re:You're misunderstanding the argument by Xest · · Score: 1

      "1. maximising free ram usage is a fallacy. If you have the entire system to yourself, then it is fine, suck up as much as possible. However, our systems do not have that luxury - I have several apps running, and if each one is written to use RAM like its going out of fashion, they'll only end up starving each other for resources. the GC will be kicking in much more often, or worse case - you'll be swapping. I understand the theory, but the practice is quite different. There's another aspect to this that people forget - RAM is not a free resource, it costs quite a bit to copy that data in and out, which we see with today's monumentally slow startup times."

      So you still don't get it in other words. High RAM usage only occurs when there's enough free RAM to make that a possibility. It wont swap because as RAM usage on the overall system increases, RAM usage for a particular Java application can decrease to match, but that doesn't mean it shouldn't increase usage when there's room to do so.

      "Performance. I know script languages are crap, but when you have a situation where a slow tool is acceptable, you'd be right to use it. UI is a slow task - human reactions are dreadful in computer terms, so if the UI can be written in script and it performs fast enough, then you'd be choosing the right tool to write your UIs with it as hopefully development time would be insignificant."

      That's true if your UI only performs simple tasks, but if you're doing something with your UI then scripting languages will be too slow, where Java wouldn't.

      "Java does not scale, absolutely not, and enterprise java is really a synonym for 'horrible crap' (think Siebel, or similar examples)."

      This is unbelievably incorrect and I can't believe you're repeating it, it shows you know absolutely nothing about the topic at hand. eBay does not use C++ for the "good stuff", it uses Java through and through. Similarly Google uses Java for much of it's backend that does need to be scalable. It's used in banking, commerce, it's used in so many places on the backend where scalability is a must that I'm amazed someone would claim it's not scalable- that's always been it'sbest bit, the fact it does handle scalable and distributed systems better than pretty much any other.

      "As it is, I am a very competent developer."

      Right, maybe within a small area of expertise, but your comments about Java are so utterly wrong it shows that your knowledge of the topic is massively limited outside of that comfort zone.

      "Maybe that's why I can code stuff up in C++ and not have to fall back on the 'easy' stuff like Java and C#."

      Hohoho. Line you up against an equally competent developer, get you to produce vast amounts of code, and I guarantee you will be slower, and your code will be more vulnerable to security exploits and issues such as memory leaks. It doesn't matter how good you think you are, these are simply the inherent disadvantages of C++ in this day and age. You're not perfect, no one is, there's no way you can guarantee your code is perfect, and there's most definitely no way you can develop as fast in C++ as you can with managed languages simply by virtue of the fact you just have to write more code with C++.

      These are the fundamental facts, if you do not get this, you are not as good a developer as you seem to think you are. Let me just restate this to make it clear- yes you can develop something in C++ to perform better than you can Java, but there is much less of a security blanket against mistakes, much more code must be written (if not only because you have to remember to manually clean up memory)- it's a simple logical implication of these facts that this inherently means you will take longer to develop with C++ and are more likely to have more serious errors, and so again, this is why there's often no point using C++ over Java or C# for most applications.

      If you still don't get it, let me just give you something to think about, because the answer and reasons are EXACTLY the same, so here goes- you surely wouldn't use C to develop dynamic web applications on the server side anymore using CGI, why do you think that is?

    9. Re:You're misunderstanding the argument by baerm · · Score: 1

      No they're not, they just better understand the argument
      than you do apparently, and Google's conclusion doesn't disagree with
      them.

      I think everyone agrees C++ can theoretically perform
      faster, but as Google notes you need to perform a lot of optimisations
      by hand which requires a lot of time, and a high degree of skill to
      perform.

      I would suggest you re-read the article (or read it). The conclusion
      was that a simply written C++ was much faster (almost an order of
      magnitude) than a simply written java program. Your argument would
      follow that Java could theoretcially perform as fast as simple
      un-optimized C++ but it would require a high degree of skill and time
      to make it that way. I.e., everyone should write their code in C++.

      The 'optimized' C++ speed was not shown, nor the 'optimized' Java (it
      just mentioned that the optimized Java was as fast as the simple C++).

      Now, the test was a narrowly defined test. And speed performance is
      not always the most important feature of a software project (maybe not
      even the majority of the time). So I think this test shows what most
      people already know. C/C++ is faster than Java. But then, for many
      (most?) projects, it doesn't matter that much and other language
      features can be more important (ease of development, familiarity,
      etc...).

    10. Re:You're misunderstanding the argument by SomeStupidNickName12 · · Score: 1

      Buddy get off your high horse!

      Your example of code professionals is wrong, the type of you developer you are describing next to useless in anything outside of academia. They will spend months/years optimizing code that could be done with a $10000 hardware upgrade. As a dev manager, these are most painful resources to manage because they have no idea on what to prioritize.

      In terms of scalability of java, what are you talking about? In an enterprise high volume transactional environment I have seen nothing coming out of the C/C++ world that can even touch java.

  59. Average? by mmcuh · · Score: 1

    Why would anyone expect average programmers to write well performing code in any language?

    1. Re:Average? by whookids · · Score: 1

      Why would anyone expect average programmers to write well performing code in any language?

      Because average programmer is not good enough and they want you to realize that you always have to learn (i.e. go from average to experienced and so on).

  60. Average programmers by oergiR · · Score: 1
    A big factor is how well the programmer knows their stuff. I basically run the same test, accidentally, when I ran a course on a university computer science curriculum. Graduate students had to program a small speech recogniser in C++, Java, or Python. I measured the speed of the entries on a standardised task. My reference version, in C++, was fastest, no surprise there. Second and third were students' programs in Java and Python (!). The very slowest program was extremely convoluted C++ code, and a factor of 20 slower than the fastest C++ version. The Java programs showed less variance: they were bland, but all reasonable. The entries in Python were concise.

    My conclusion is that the performance advantages of C++ are easily offset by its ability to confuse the programmer. C++ is arcane and complicated; Java is more limited; Python is a lot cleaner. If you know exactly what you're doing, then C++ can be the fastest option, but in real-life situations, with deadlines and average programmers, don't go there.

  61. How not to write a research paper by Anonymous Coward · · Score: 0

    I can only assume that this is a non-reviewed whitepaper rather than a journal paper, because the results are useless. They fail to specify the compilers used, the compiler options, the target CPU (thus making the binary size comparison meaningless). The conclusion that "C++ wins out by a large margin" can't be supported unless you take a representative sampling of compilers for each language. Heck, they haven't even used gcj in the comparison (and I think gcc vs gcj would be a much more interesting comparison since it'll be more-or-less the same backend).

  62. Why don't people use smart pointers? by master_p · · Score: 1

    I've read the entire thread, and one common complain about c++ is manual memory management.

    So, my question is this: why don't people use smart pointers? boost has the class boost::shared_ptr which works with lots of compilers, and the upcoming c++ will have std::shared_ptr.

    With smart pointers, there is no need to manage memory manually. I've written whole apps (130-150Kloc) without a single delete statement and without a single memory issue by using smart pointers.

    1. Re:Why don't people use smart pointers? by shutdown+-p+now · · Score: 1

      Reference-counting smart pointers do not completely deal with the problem, as you can still have reference cycles. Judicious use of weak pointers usually solves all but the most convoluted cases, but you have to be aware of the problem to begin with, and understand ownership and other dependencies in your data structures well to come up with a proper arrangement. Whereas, in something like Java, if you need a tree where child nodes know their parent and parents know their children, it's a simple and straightforward object reference on both sides, and GC takes care of the rest.

      Also, a long-standing problem with smart pointers in C++ has been that the only standard one was auto_ptr, and it was 1) overly simplistic (no sharing), 2) had abominable semantics (silent move in operations which normally copy), and 3) was unusable in standard collections. You could always write your own better smart pointer, of course, but if every library does that, then using them together is a nightmare.

      Finally, until move semantics were added in C++0x, there was a general problem using smart pointers in STL containers such as std::vector - you were effectively forced to use something that permitted sharing (such as shared_ptr), even though the container was the only owner of the pointer in practice, just so that the container could create temporary copies while reallocating the underlying storage. The problem with this arrangement is that shared_ptr and similar solutions have a fairly noticeable perf penalty - you pay to allocate the refcounted block for every object (unless using intrusive smart pointers, where counter is part of every object), and then you also pay for updating those refcounts.

    2. Re:Why don't people use smart pointers? by master_p · · Score: 1

      Reference-counting smart pointers do not completely deal with the problem, as you can still have reference cycles.

      True, but the need to have cyclically referenced data structures doesn't come up very often in code. I've been programming for 14 years, and I rarely had to deal to with cyclic references.

      Also, a long-standing problem with smart pointers in C++ has been that the only standard one was auto_ptr, and it was

      Boost had smart pointers for a long time now. The new C++ has them in the standard library.

      Finally, until move semantics were added in C++0x, there was a general problem using smart pointers in STL containers such as std::vector - you were effectively forced to use something that permitted sharing (such as shared_ptr), even though the container was the only owner of the pointer in practice, just so that the container could create temporary copies while reallocating the underlying storage. The problem with this arrangement is that shared_ptr and similar solutions have a fairly noticeable perf penalty - you pay to allocate the refcounted block for every object

      When a shared_ptr vector reallocates its storage, the newly created ptrs are copy-constructed from the old ones, and so there is no allocation of refcounted block.

      (unless using intrusive smart pointers, where counter is part of every object), and then you also pay for updating those refcounts.

      Well, now that C++ has move semantics, and shared ptrs in the standard library, are there any other complaints? these problems are solved, so I don't see how C++ cannot be a viable solution for long and big projects.

    3. Re:Why don't people use smart pointers? by shutdown+-p+now · · Score: 1

      True, but the need to have cyclically referenced data structures doesn't come up very often in code. I've been programming for 14 years, and I rarely had to deal to with cyclic references.

      They are actually much more common in GC languages like C# or Java, which leads me to suspect that programmers using languages with reference counting purposely avoid this kind of structure because it is known to create problems in such languages. Most often, I see that appear in trees where parent nodes know about their children, and child nodes know about parents. Pretty much any object model for use with an ORM in C# or Java has such an arrangement.

      Boost had smart pointers for a long time now.

      True, but to many Boost is just another third-party library, and its solutions don't really take precedence. Also, many library authors do not want to depend on Boost.

      The new C++ has them in the standard library.

      Yes, we've had that stuff since C++ TR1. But compilers have lagged somewhat implementing that in practice, so we've only had, what, about 3 years of having stable implementations of those on all major platforms?

      But yes, now it's going to change. But there is still plenty of C++ code written before TR1 or C++0x, and that is going to stay with us for a long time to come. Then, of course, there are all the people learning the language from "C++ for Dummies" books, which often don't even explain auto_ptr, much less the new stuff...

      When a shared_ptr vector reallocates its storage, the newly created ptrs are copy-constructed from the old ones, and so there is no allocation of refcounted block.

      Yes, you don't pay that price on every reallocation, but you do pay it when initially adding an element to the vector (or other container). On reallocation, you only pay for refcount updates.

      Also, some implementations used template trickery to enable special handling for types in std (which they're allowed to do), where the use of copy ctors and operator= was replaced with std::swap against a freshly constructed temporary, effectively emulating move semantics in C++03. Visual C++ (since 2008) is one notable implementation that does so; no idea about g++. This is particularly helpful for vector of shared_ptrs. Unfortunately, this cannot be generalized to user-defined types (e.g. if you use Boost smart pointers rather than std ones), because the container is required by spec to do copies and not swap() in C++03 - the only reason why it can make an exception for types in std is because those are controlled by implementation itself, and it knows where swap() has exact same observable behavior.

      Well, now that C++ has move semantics, and shared ptrs in the standard library, are there any other complaints? these problems are solved, so I don't see how C++ cannot be a viable solution for long and big projects.

      For starters, we need that FCD to become a Standard :)

      Then, we need to educate people about what's in that standard. C++ is a huge thing, and many people who think they know it have barely touched the surface - and yet work on large-scale projects.

      C++ was always a viable solution for long and big projects, as evidenced by the fact that a lot of complicated desktop software (e.g. MSOffice, Photoshop, KDE, ...) and games are written in it. But memory management is not the only thing that makes C++ harder than C#/Java "for the masses", and so the latter will keep being used for projects where performance or memory footprint are not critical, whereas concise, easy-to-maintain code (without requiring a full team of experts) is.

  63. If you want performance use a compiled language by Required+Snark · · Score: 1

    Look at performance critical applications: signal processing, image processing, graphics, data base implementation, operating systems. Any time performance is high on the list people pick C, C++, Fortran, and sometimes ADA. Compilation is the only feasible choice. One thing that compilers give is the ability to tune the algorithm based on real execution profiling. If you don't compile at some point you will run into language implementation decisions that are out of the coderscontrol, and you will hit a wall. This means more work, but greater effort gives better results. If other things like programmer time or ease of modification are important then non-compiled languages may be better. One size does not fit all.

    --
    Why is Snark Required?
  64. This is JEOPARDY! by mgpl777 · · Score: 1

    Alex Trebek: This language has the best performance. It's almost "D".
    Watson: What is JAVA?

  65. C++ wins versus bytecode and interpreted languages by sbrown123 · · Score: 1

    Is this actually news worthy? A better question is: which one allows programmers to perform better? I'm not just talking lines of code, but rather how much time is spent developing in general. I guess that would be hard to measure but it would make for a far better research paper.

  66. Performance bottlenecks are from bad algorithms by Goonie · · Score: 1

    After teaching programming for a while now, it's my very strong suspicion that far more performance bottlenecks are caused by programmers who don't even understand what time and space complexity is, than are caused by competent programmers implementing in one language over another.

    For instance, I just set a scripting assignment (to be completed in bash 3.0, which lacks associative arrays) which asked students to process syslog files and report how many times different applications appeared in the logs. Some students did this by repeatedly using grep and wc over the entire log file, and wondered why I deducted marks when it took a minute to run on moderately large logs.

    God help anyone who uses a program they've written.

    --

    Any sufficiently advanced technology is indistinguishable from a rigged demo
    --Andy Finkel (J. Klass?)
    1. Re:Performance bottlenecks are from bad algorithms by SomeStupidNickName12 · · Score: 1

      Have to disagree with you on this one. I agree that what your students are doing is extremely inefficient but if you writing a script in bash, you should be using grep and wc repeatedly. Bash scripts are supposed to be very quick to write scripts that do a job. If you need to to parse the logs faster and more efficiently then bash is the wrong choice for you and its time to look at perl.

      Correct tool for the job.

  67. Delphi/Object Pascal was the same, later, too! by Anonymous Coward · · Score: 0

    Additionally - You're right on that, because it also held true into later years (1997-1998) when, in of ALL places (a competing trade magazine), Delphi/ObjectPascal 7, did great on a series of tests in VB Programmer's Journal Sept./Oct. 1997 issue "Inside the VB5 Compiler Engine"!

    That's where Borland Delphi (Object Pascal 7 really) knocked the chocolate out of BOTH VB & MSVC++...

    Especially in the MATH & STRINGS tests, Now - Mind you, EVERY PROGRAM WORKS ON MATH & STRINGS!

    (However, I don't *think* I have to tell YOU, that - especially if you've been coding since then, but, that's for everyone else's benefit who doesn't code).

    Delphi nuked VB right outta there, hugely (Java too of course), AND MSVC++ TOO (by a couple orders of magnitude).

    In fact, it took "1st place" in 2-6 tests given (pretty much "even split" w/ C++, as far as wins, but MUCH better in results overall):

    RESULTS:

    ---

    Strings (Delphi - by a 50%++ margin over C++)

    Math (Delphi - by a 50%++ margin over C++)

    TextBox form loads (C++ won this, by .001% margin over Delphi only)

    Native-to-Language Graphics Methods (C++ won this, by 1% margin over Delphi only)

    API Graphics Methods (C++ won this, by .5% - SMALL MARGIN)

    ActiveX form load (VB won this, only 1 it did)

    ---

    Additionally & Lastly:

    Where Delphi/Object-Pascal won, it won by GIGANTIC margins... Especially in MATH & STRINGS!

    (IIRC, It's because of how Pascal handles strings iirc (C/C++ read "right to left" whereas Pascal reads "left to right", or something along those lines)).

    In fact - It's the "why" of WHY I started using it back then, over both VB, & MSVC++, for years for personal AND work projects (where it was allowed, most places were MS shops)

    APK

    P.S.=> Thus, you can see how Pascal's a great language for speed/performance... even back in those days!

    ...apk

    1. Re:Delphi/Object Pascal was the same, later, too! by gay358 · · Score: 1

      I am not sure what you mean by handling strings right to left (parsing?), but the main difference between traditional C and Pascal was that C strings usually didn't have explicit length anywhere (the string just continued until there was first 0x00 character) where as the first element of Pascal string was the explicit length of the string (at least in Borland Pascal the maximum length of a normal string was 255 characters for this reason).

      Both of these approaches have pros and cons (and sometimes zero ended strings were used in Pascal and some C functions expect explicit length information). And Borland Pascal in some version supported also special strings that you could use as both Pascal and C style strings (they had explicit length at the beginning of the string like normal Pascal strings, but they also had extra 0x00 byte after the end of the string) which was quite useful, if you had to call some external functions/procedures which expected C style string parameters.

  68. Believe it man (proofs inside link) by Anonymous Coward · · Score: 0

    http://developers.slashdot.org/comments.pl?sid=2239636&cid=36448994

    And, the compile speeds? Due to something I noted in how Pascal handles strings vs. C/C++... see that link above.

    APK

  69. Brainfuck is the fastest! by Czubaka · · Score: 1

    We all know Google and Microsoft Bing are internally implemented in Brainfuck. We don't they simply admit it? They're trying to hide that fact by publishing language-comparison mumbo-jumbo while using the specially crafted Brainfuck processors to keep their domination.

  70. C++ is beaten hollow by Fortran by 140Mandak262Jamuna · · Score: 1
    It is a totally biased test. They would use some terminology like "Object Oriented" and disqualify Fortran from running. Throwing the word "object" does not make it objective. Fortran will beat C++ hollow.

    Just that you will go mad figuring out the Hollerith field way of specifying strings and will never complete the project. But if you actually got the code to compile and run, Fortran would be the most awesomest language.

    --
    sed -e 's/Chuck Norris/Rajnikant/g' joke > fact
  71. NOT best 'on the market' by Anonymous Coward · · Score: 0

    Wait, wait, wait ... "[Google] implemented a compact algorithm in [...] C++, Java, Scala and [...] Go" and C++ was the 'best performing' OF THOSE FOUR. Not best on the market, best OF THOSE FOUR. To which I say ... of course it is.

    Now, you wanna go ahead and put C and ASM in there? C++ won't make it.

  72. Um... err... by Millennium · · Score: 1

    So they ran a test between two statically-compiled native-code languages and two dynamically-compiled bytecode languages, and then seem surprised when one of the native-code language wins?

    I'm also noticing a marked lack of C# (not something I'm personally a fan of, but nothing if not a mainstream competitor to the languages listed) and Python (another language that gets "used for real stuff" inside Google) in the test. Why is that? Not that I'd expect Python to do very well in a performance test against languages like these, but it still seems an odd omission.

  73. Not another evangelistic pissing match!? by Anonymous Coward · · Score: 0

    Google are currently preparing a paper comparing Linux and Windows... Linux will win on technical grounds, but Windows will get props for nice icons and user friendly dialogs.

  74. So what would be faster by Anonymous Coward · · Score: 0

    PHP (easy/fast to develop in and maintain) on a modern chip.

    -or-

    ASM/C on an old chip.

    My point - as chips get faster the benefit lies in the code creation/maintenance/portability & ease of use with high level languages.

  75. Multi-processing by goombah99 · · Score: 1

    Low level languages like C++ are highly optimized for the current computing environment. But they are hard to program. The future belongs to programming environments that are.
    1) hard for a programmer to understand because they are data flow or multi-processing or highly data-local (cache optimized) or syncronous (GPU).

    2) the environment may be unknown or variable not fixed. you may not know where your program will be executing from day to day or what the specs of the machine are.

    Languages good at this don't exist yet. And we have not even begun to tap functional programming's potential.

    The other problem with C++ is it's very easy to make logical errors in.

    --
    Some drink at the fountain of knowledge. Others just gargle.
  76. Did they test against hand-tuned ASM by Anonymous Coward · · Score: 0

    If the C++ needed extensive tuning beyond the abilities of the average programmer, why not also test against hand-tuned ASM. I can't think of many instances where C++ would beat it if the difficulty of coding were ignored as it was for C++

  77. C++ tuning really...involved by Anonymous Coward · · Score: 0

    One thing that struck me in the paper is just how much of the need for C++ tuning seems to arise from complexities of the standard library components, or just of C++ itself. I have to say at this point I prefer to work in C, with libraries I understand well.

  78. VB6 is clearly the winner here... by DarthVain · · Score: 1

    Besides, different languages are better at different things. I bet Assembly is a heck of a lot faster than C++, but I wouldn't want to try coding many of the applications that use C++ into Assembly.

  79. Performance is always critical ... by Paul+Dubuc · · Score: 1

    ... eventually; often when its too late to do anything quick, easy or cheap to make it better.

  80. Too bad by Anonymous Coward · · Score: 0

    From personal experience, most of Google's developers don't know C++, including a great many who claim the do but really don't. I guess this is a problem for Google.

  81. Poor LaTeX skills often mean poor at C++ by james_marsh · · Score: 1

    Given the number of Googlers involved with producing this article, I'm more surprised by them not using TeX quotation marks correctly than the result of the competition. (Not to mention using crappy tables with way too many ruled lines which do nothing to aid understanding of the organisation of the tables.)

    Experience frequently shows that people that overlook such details writing an article will often by nature be weak C++ team programmers. More than with most other languages, good C++ coding demands someone who is intrinsically observant, obsessively perfectionist and aware of often obscure side effects and implications of everything they write. This is obviously important on the most basic level so that they don't make mistakes, but even more important that they understand how other people could misinterpret complex code and algorithms and potential consequences.

    It is this last level of empathy that is the sign of great C++ programmers vs. the good or clever. "Clever" solitary programmers (such as some of those drawn to perl) are in fact the worst to have in C++ team programming scenarios where their desire to demonstrate their own ability often ends up with some over-templated prematurely optimised nightmare which is then left as a trap for someone seeking to modify it later on.

  82. tuning considered bad by Anonymous Coward · · Score: 0

    Systems that require "tuning" for good performance are inherently bad. Think about old TV sets that had fine tuning knobs. The knob was only there to compensate for unstable internal oscillators. In electrical engineering terms you have a high Q system. A high Q system means that small perhaps uncontrollable changes in inputs causes large changes in output. In software terms small changes like a compiler revision, processor change, etc can cause big changes in performance.
    The fact the C++ programs can and perhaps must be hand optimized by humans is a sign of the immaturity of the technology. It is not a benefit but a disadvantage.

  83. Like how? by Sycraft-fu · · Score: 1

    I fail to see anything looking over Java's spec that doesn't match to the capabilities provided by Intel and AMD's SSE2 implementation. So what, precisely, is it that Java is doing that keeps it from using the massive amount of FPU power present on modern processors?

    Also if that is a problem Java has, well then that is a major performance issue right there since most performance intensive apps these days are FP heavy. When people start talking about wanting to crunch a lot of numbers, they are usually talking FP. 3D graphics, games, audio processing, EM simulation, etc you are talking FP heavy stuff. If Java is going to run at about 2% speed, that is a real issue.

  84. Java is useless for scientific programming by Brannoncyll · · Score: 1

    The lack (by choice apparently) of operator overloading cripples this language for any scientific application. They say they chose to deny operator overloading because it produces 'obfuscated' code. I would reply with something along the lines of:

    c++:

    Matrix A,B,C;
    Matrix D = A*A+B/C + A*C

    Java:

    Matrix A,B,C;
    Matrix D = A.mult(A).plus(B.div(C)).plus(A.mult(C))

    Although my Java is pretty rusty, i'm pretty sure the more obfuscated code is definitely not the c++! Now try moving this to a massively parallel environment.

    1. Re:Java is useless for scientific programming by Brannoncyll · · Score: 1

      .... for some definition of matrix division of course!

    2. Re:Java is useless for scientific programming by VortexCortex · · Score: 1

      o_O

      Are you implying that what the source code looks like has anything to do with its ability to be used in mathematical models
      For Science?

      Also: "useless" -- I do not think this word means what you think it means...

    3. Re:Java is useless for scientific programming by Brannoncyll · · Score: 1

      Yes actually.

      As a physicist I regularly write code for particle simulations for use on supercomputers and clusters, as well as for data analysis on workstations. If we were using Java the code would be virtually impossible to debug or maintain as the developer would have to spend insane amounts of time decoding the obfuscated fit formulae to find the error or understand what's going on.

      I guess if you were some sort of masochist then you might decide to take the Java route, so in that sense it is not totally useless, but for my purposes and those of my collaboration, the language is essentially so, in that it would be stupid and ridiculous to use it. This is evidenced by the fact that I have written and used simulation/analysis code in C, C++, perl, python, Fortran, Mathematica, heck, even assembler, but never, not once, Java.

      In addition, I have been a TA on an undergraduate course on scientific programming in Java, so I have firsthand experience with how much of a pain it is to use.

  85. Java strings are more Pascal-like by Estanislao+Mart�nez · · Score: 1

    Let's not forget that Java strings are more similar to Pascal than to C. A string in Java is an object that encapsulates a char[], a start index and a length. So for example, taking a substring from i to j is O(1) in time and memory for Java—it just returns a new String object with the same char[] but a new start index and length.

  86. C++ faster: the great C++ conspiracy by formfeed · · Score: 1

    The interesting part is not that C++ is faster, but that it was quite comparable to Java and only became much, much faster after several Google engineers optimized it!

    Let this be the final evidence in what I call the "great C++ conspiracy":

    Good coders make good code. If you want the fastest code you have to go beyond compiler optimization. You need programmers who are not only at the top of their field, but can dream in code. So, if you want a language to reliably produce the best results, you have to make sure that it attracts the right kind of people and kills the weak.

    A language that only works for people who have given up any regular sleeping patterns, social ties, and hope. A language that will cause any sane person to stab themselves with a null pointer. A language where operators can be overloaded, and anything could mean anything else in a different context. Beautiful if done right, but treacherous and deadly to the uninitiated. What better, than to design a language that is the coding equivalent of walking through Mordor!

    1. Re:C++ faster: the great C++ conspiracy by ImprovOmega · · Score: 1

      More to the point, good algorithm design will always trump compiler optimization tricks.

      My heapsort will always beat your insertion sort on arrays over 1000 or so elements, no matter what language/compiler/optimization tactics are used.

    2. Re:C++ faster: the great C++ conspiracy by smellotron · · Score: 1

      More to the point, good algorithm design will always trump compiler optimization tricks for sufficiently large inputs.

      FTFY.

      My heapsort will always beat your insertion sort on arrays over 1000 or so elements, no matter what language/compiler/optimization tactics are used.

      Can I pick adversarial languages and element types? You get bash and [ (a.k.a. test ). Your language forks a new process for every comparison. Shouldn't be too difficult to beat.

      My point: constant factors matter.

  87. RTFA by Anonymous Coward · · Score: 0

    I know it's aweful to actually RTFA. but, the Java tuned implementation actually reached the speeds of the original implementation in C++, but then the C++ was tuned further. Moreover, the dev (Jeremy) refused to apply additional optimizations to the Java implementation (the paper does not say why) but the authors did say that the C++ optimizations could be applied to the Java implementation (assuming that it would make the Java implementation even faster).

    So, not sure why the hate has to go on about 'Javaheads', but most of the comments found here about Java speed are based on misinformation and causes the Java advocates to come out and speak up about the truth.

  88. For when your only value metric is run-time speed.

    Of course, if you actually have to take into account stuff like speed of adding features to the system, or skill-level of available programmers, or robustness, you're probably better off using anything else. Fortunately, most software is not speed-critical and you can use more reasonable programming languages.

    C++ is a good language... but only for the limited circumstances in which it excels. Otherwise, the overhead entailed in coding in it isn't worth the cost.

    --
    That is all.
  89. selection bias by Anonymous Coward · · Score: 0

    '...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.'"

    Actually, if we define "programmer" to be someone who can perform such tuning then it's 100%. Those who cannot perform such tunings would be "wasted protoplasm".

    1. Re:selection bias by Anonymous Coward · · Score: 0

      Well, certainly, if we change the meanings of words, we can make anything equal anything.

  90. Function call parm passing, AND string parsing by Anonymous Coward · · Score: 0

    String parsing goes right to left in C/C++ & the reverse in pascal iirc/afaik, AND, function call parameter passing on x86 is different in them also, ala:

    (PAY ATTENTION TO THE BOLDS BELOW TO SEE WHAT I MEAN)

    pascal: Based on the Pascal programming language's calling convention, the parameters are pushed on the stack in left-to-right order (opposite of cdecl), and the callee is responsible for balancing the stack before return. This calling convention was common in the following 16-bit APIs: OS/2 1.x , Microsoft Windows 3.x, and Borland Delphi version 1.x.

    register: An alias for Borland fastcall.

    stdcall: The stdcall calling convention is a variation on the pascal calling convention in which the callee is responsible for cleaning up the stack, but the parameters are pushed onto the stack in right-to-left order, as in the _cdecl calling convention. Registers EAX, ECX, and EDX are designated for use within the function. Return values are stored in the EAX register. stdcall is the standard calling convention for the Microsoft Win32 API and for Open Watcom C++.

    Microsoft fastcall: Microsoft or GCC __fastcall convention (aka __msfastcall) passes the first two arguments (evaluated left to right) that fit into ECX and EDX. Remaining arguments are pushed onto the stack from right to left.

    Borland fastcall: Evaluating arguments from left to right, it passes three arguments via EAX, EDX, ECX. Remaining arguments are pushed onto the stack, also left to right. It is the default calling convention of Borland Delphi, where it is known as register.

    ---

    * And you're right, afaik, about null terminated strings as well as pascal strings carrying their length 'built in'.

    APK

    P.S.=> I don't/didn't know if you recall "stdcall" vs. "pascal" calls also, but that's another diff., per all of the above, in function calling parm passing too!

    ... apk

    1. Re:Function call parm passing, AND string parsing by gay358 · · Score: 1

      It has been so many years since I last programmed using x86 assembly, that I didn't remember all the differences between Pascal calling convention and C convention. I did remember the difference in cleaning stack (caller/callee) when function/procedure ends, but I didn't remember difference in the order which parameters were pushed to stack and I didn't remember which registers were used in function calls.

      However, as far as I know, this has little to do with parsing source code or strings. And as ar as I know, the typical way to parse strings in C (eg. strtok) and Pascal tends to be from left to right (source code, after it is tokenized is different matter). However, parsing programming languages is often done from right to left, but this depends on the implementation of the parser. It is also so many years since my compiler course, that I cannot remember if there are some programming languages, that absolutely must be parsed in some particular direction.

  91. U can get lengths of C strings ahead of time by Anonymous Coward · · Score: 0

    I am PRETTY SURE you can get the length of a C string ahead of time, by using a simple trick:

    That's by setting up 2 pointers to vector thru it!

    Both start @ "zero-th", & the second is ALWAYS DOUBLE THE FIRST...

    (You need to 'err-trap" this, because the error on the 2nd pointer failing to advance, is what gives you the length of said string (by doubling the first "1/2 sized pointer")).

    APK

    1. Re:U can get lengths of C strings ahead of time by gay358 · · Score: 1

      I am not sure if I understand what you mean. Of course, you can manually keep track of the length (or have pointer also to the end of the string) of C style strings, if you want to and sometimes it is done for performance or safety reasons.

      But by default/convention, strings in C tend to be just pointers to the first character of the string and where the only way to find the length/end of the string is going forward until you find the first 0x00 character. And often the string is truncated by just writing new 0x00 character somewhere between start of the string and previous end of the string. The same trick can often be used for splitting string to separate tokens/strings in place -- without copying data anywhere.

  92. Oh, Delphi/Object Pascal strings too? Check it by Anonymous Coward · · Score: 0

    You're describing "shortstrings" here:

    "at least in Borland Pascal the maximum length of a normal string was 255 characters for this reason" - by gay358 (770596) on Wednesday June 15, @12:50PM (#36452342)

    Also, so you know?

    In 32-bit Delphi @ least??

    You could use a compiler directive to force shortstrings vs. std. strings, by placing it around various blocks in your code:

    E.G.: (1st one turns OFF normal strings, 2nd turns them back on)

    $H-

    Your function or procedure would be here...

    $H+

    OR, by declaring the variable used as a type shortstring, either globally, or inside the function/proc using it.

    var
          StringVar : String;
          SmallStringVar : ShortString;

    APK

    P.S.=> Iirc, the "advantage" was one used the heap, & the other, the stack (but, I am getting "dim" on this one here, as it's been quite a few years since I coded any Delphi, 2006 iirc (used to be my "fav" too, & for many years!))... apk

    1. Re:Oh, Delphi/Object Pascal strings too? Check it by gay358 · · Score: 1

      I think Borland/Turbo Pascal had only strings that were shortstrings (and some versions of Borland Pascal supported also C style strings relatively well). I always wished that they would support longer strings and it is nice to hear that they increased maximum length of Pascal style strings in Delphi. I used lot Turbo/Borland Pascal, but I have never used Delphi and I am not familiar with it.

      Nowadays I use mostly just Java, C(++) and Perl, but sometimes I feel that I should try using Pascal again as I really liked it. I recently noticed that there is cross platform IDE/library called Lazarus which is some kind Delphi clone. Perhaps I should try it. On the other hand, maybe learning Scala or OCaml would be even more useful...

  93. Average programmer? by bored · · Score: 1

    Your average programmer either isn't doing C++ or won't be for long...

    That is not to say its a bad language, but its like giving a kid a table saw or oxy acetylene torch. Sooner or later something bad is going to happen. Made worse by the fact that every single person doing C++, thinks they are an expert and proceed to use every obscure feature at the same time.

    1. Re:Average programmer? by VortexCortex · · Score: 1

      Yep. Look at RISC... Reduced instruction set, means lower power consumption, smaller chip size and complexity.

      Having a whole bunch of features tacked on is good when they are used by everyone all the time -- It's best to get rid of the features you really don't need to make it easier for the chip fabricators and/or computer programmers.

      C++ is the absolute worse. It's the only language I've encountered where an entire other language lives inside it and slowly killing it like a parasitic twin. As a C++ coder I'm not supposed to use the C specific features because "C is not C++", and yet, it is... Thus, crazy semantic workarounds for things that should be simple, but conflict with the base language, are shoehorned in.

      I like C++, and I understand that C++ was born by adding features to C, but it's time to cut that umbilical cord. C and C++ can live on separately -- well, they could have if they would have made the decision to split before so much code was written...

      C'est la vie. Some people never learn. Riding the coat-tails of another language is a strategy that can yield results in terms of popularity (see: JavaScript) -- However it comes at the price of confusion (JavaScript is not Java; C++ is not C), and in C++'s case, unnecessary complexity -- the very enemy of "performance" in every sense of the word.

      To say that C++ is designed for high performance, when in fact it was designed for popularity and ease of migration / incorporation for C coders and existing C (and C++) code, is not only a lie but a false premise that corrupts the very language itself.

    2. Re:Average programmer? by ultranova · · Score: 1

      C++ is the absolute worse. It's the only language I've encountered where an entire other language lives inside it and slowly killing it like a parasitic twin. As a C++ coder I'm not supposed to use the C specific features because "C is not C++", and yet, it is...

      C? I thought you were talking about templates.

      So, is carrying two parasitic twins twice as bad as just one ?-)

      --

      Forget magic. Any technology distinguishable from divine power is insufficiently advanced.

  94. Complete nonsense by SoftwareArtist · · Score: 1
    The paper even admits these comparisons are completely invalid. From the "Java Tunings" section:

    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 they intentionally optimized the Java version much less than the C++ version, and they know the Java version could be sped up by applying the same optimizations they used for the C++ version. And (who would believe it?) the C++ version came out faster than the Java version! What a surprise!

    Truly nothing to see here. Please move along.

    --
    "I'm too busy to research this and form an educated opinion, but I do have time to tell everyone my uninformed opinion."
  95. Likewise on the SPECIFICS of stringwork in by Anonymous Coward · · Score: 0

    Compilers here... much as yourself on function calling conventions:

    "It has been so many years since I last programmed using x86 assembly, that I didn't remember all the differences between Pascal calling convention and C convention." - by gay358 (770596) on Wednesday June 15, @04:58PM (#36455160)

    I understand fully, hence, in my init. reply which you are noting now on stringwork (and in my subject line above now?) - I did state "iirc" & "something along those lines", indicating not TOTAL surety on my end!

    In fact, quoting myself again from it:

    "(IIRC, It's because of how Pascal handles strings iirc (C/C++ read "right to left" whereas Pascal reads "left to right", or something along those lines))." - by Anonymous Coward on Wednesday June 15, @09:00AM (#36448994)

    So, you're probably right (now that I think about it) below - I can "err" or be unsure, as I was above...

    Above ALL else: I don't design compilers, I just use them!

    I get hazy too (getting old here, 48 yrs. old almost now). I never thought I'd say that, but... I think it's starting, lol!

    ---

    "However, as far as I know, this has little to do with parsing source code or strings. And as ar as I know, the typical way to parse strings in C (eg. strtok) and Pascal tends to be from left to right (source code, after it is tokenized is different matter). However, parsing programming languages is often done from right to left, but this depends on the implementation of the parser. " - by gay358 (770596) on Wednesday June 15, @04:58PM (#36455160)

    Again - You're probably the one who's correct on the strings parsing, especially now that I think about it...

    I just KNEW there were things that PASCAL does, left-to-right (function call parm passing, tokenizing, etc.) that C/C++ don't.

    * Anyhow - good discussion & review for me @ least! Thanks...

    APK

    P.S.=> Heh, something you MAY be "interested in" or find pretty cool possibly:

    I put up a "little trick" in my other replies to you that pretty much does what a PASCAL "sizeof" does, in regards to finding out string lengths in C/C++ even... but, then again? C/C++ probably HAVE a sizeof too!

    Anyways - the trick? Should work! You're probably going to know that already, but it's pretty neat...

    Oh - I also noted you put out strings in 16-bit type - std. String type!

    (Hence, I think why you cited BORLAND PASCAL (I called it Turbo Pascal, but iirc, there was a "Full-Blown BORLAND PASCAL too, just like there was Turbo C++ & Borland C++ too)

    Anyow - There, I noted that Delphi (in 32-bit) used String AND ShortString (couple ways to do it too, that you can still use in practice in Delphi)... & the advantage I am no longer even 'sure of 100%', but it had something to do with heap vs. stack usage, iirc & memory use too! apk

  96. Yup, noted it in my other reply to you by Anonymous Coward · · Score: 0

    Yup, I noted it in my other reply to you here:

    http://developers.slashdot.org/comments.pl?sid=2239636&cid=36455494

    In regards to this:

    "I think Borland/Turbo Pascal had only strings that were shortstrings (and some versions of Borland Pascal supported also C style strings relatively well). I always wished that they would support longer strings and it is nice to hear that they increased maximum length of Pascal style strings in Delphi." - by gay358 (770596) on Wednesday June 15, @05:17PM (#36455420)

    Right! You were talking 16-bit is why in BORLAND PASCAL/Turbo Pascal - I was talking Borland Delphi 2.0 onwards, which was 32-bit...

    Hence, my noting the diff. between shortstrings &/or std. string types there.

    Memory use & I am FAIRLY sure heap vs. stack allocation were the advantages though as I stated.

    ---

    "Nowadays I use mostly just Java, C(++) and Perl" - by gay358 (770596) on Wednesday June 15, @05:17PM (#36455420)

    Ha, & good for you: You're "cross-platform" that way... I recently got into Python for the SAME reasons (& I do Java here as well)!

    Cross platform coding being my reasons really!

    Delphi had Kylix going & killed it, which sux... it did code in static single .exe form too for BOTH platforms (you didn't need runtimes, which = speed really). There, You could VERY NEARLY "write once, run anywhere" IF you avoided diff.'s in say, sockets work, or filesystems (driveletters in Windows. vs. mounted devices on NIX) etc.

    I took a peek @ REALBASIC too, because it does true single .exe files on Macs, Linux, AND Windows (just noting it in case you hadn't heard of it & are interested in such things & capabilities in languages - I am, because you can ALMOST "write once, run anywhere" that way).

    ---

    "but sometimes I feel that I should try using Pascal again as I really liked it. I recently noticed that there is cross platform IDE/library called Lazarus which is some kind Delphi clone." - by gay358 (770596) on Wednesday June 15, @05:17PM (#36455420)

    There is, & that one, I've tried... it is nearly EXACTLY like Delphi is in the IDE, in fact, unbelievably so!

    However - I couldn't "get it going" with the 64-bit version of FREE PASCAL (which is what Lazarus used) & I am not sure if the dev. still works on it anymore or not!

    HEY - I'd LOVE to have Delphi in 64-bit here, & NOT the .NET runtime driven stuff only (which is what Delphi became after Delphi 7).

    I.E.-> I liked building "true stand-alone executables" is why (yes, yes, I know - every app has dependencies on the API libs/dlls, but I like avoiding runtimes IF possible too).

    ---

    "Perhaps I should try it." - by gay358 (770596) on Wednesday June 15, @05:17PM (#36455420)

    Perhaps! I think you'll like it, & afaik? Lazarus works "right off", IF you stay 32-bit with it...

    Again, I couldn't get it to work right with the 64-bit version of FreePascal but... it's been about a year since I looked @ it last as well (things MAY have changed).

    APK

    P.S.=> You would have LOVED Delphi, & I think you'll like Lazarus/Free Pascal... & nice talking to you! apk

    1. Re:Yup, noted it in my other reply to you by gay358 · · Score: 1

      BTW, if I remember correctly, the latest Borland Pascals did offer some kind 32-bit support (using DPMI?). However, I cannot remember any details about it.

  97. I haven't been expressing myself well so... by Anonymous Coward · · Score: 0

    What I noted does PRETTY MUCH what C/C++ & PASCAL's "sizeof" does (I am pretty sure @ least), albeit with strings:

    Take a string, let's use 'mellow'.

    If you put 1 pointer thru it, @ 1/2 the size of another (or rather, one pointer thru it and one other one always positionally DOUBLE THE SIZE OF IT)? You can find the length of a string in C/C++ that way (just a 'trick' really).

    Understand now?

    APK

    P.S.=> Think positionally!

    E.G.:

    First pointer is at location 1 in 'mellow' (m), the second 'double size' one is at 2 (twice it's size, (e)).

    First pointer advances to 2 (e), the second 'double size' one is now at 4 (l)...

    And so on, until you "errout/abend" (which the doublesized 2nd pointer WILL do, which is why I noted errtraps like Try-Catch/Try finally (etc., same idea, JAVA, Pascal, Python & other languages have that errtrap construct)).

    In the end, in the errtrap? 1st pointer - 1/2 sized one SHOULD BE MIDPOINT & doubling it is length of string (character array really)!

    That, or use the last result of the 2nd doublesized pointer prior to abend, & bingo - size of string! apk

    1. Re:I haven't been expressing myself well so... by gay358 · · Score: 1

      I still think I am not able to understand what you mean. I guess I would need source code example to understand it. :)

      It is true that you can use sizeof if some string situations (at least with static character arrays and literals, I cannot think any other uses at the moment), but it doesn't work for example in dynamically allocated strings:

      #include <stdio.h>
      #include <string.h>
      #include <stdlib.h>

      int main() {
          char s1[] = "1234567890";
          char *s2 = "1234567890";
          char *s3 = strdup(s1);
          printf("sizeof=%ld\n", sizeof(s1));
          printf("sizeof=%ld\n", sizeof(s2));
          printf("sizeof=%ld\n", sizeof(s3));
          printf("sizeof=%ld\n", sizeof("1234567890"));
          free(s3);
          return 0;
      }

      prints:

      sizeof=11
      sizeof=8
      sizeof=8
      sizeof=11

  98. Delphi does for SURE (Delphi 2.x-Delphi 7.x) by Anonymous Coward · · Score: 0

    32 bit full support, that I know, for a fact, AND the "way I like apps", as "stand-alone single .exe files" ala:

    ---

    APK Registry Cleaning Engine 2002++ SR-7:

    http://www.techpowerup.com/downloads/389/foowhatevermakesgooglehappy.html

    ---

    Amongst around another 30-40 apps I put out as shareware/freeware over time (did a LOT of that as a student in the early to late 1990's & "finalized them all" by 2001).

    I loved it, hence, why I WISH there was a 64-bit Delphi that didn't use a runtime for .NET!

    ---

    You're probably RIGHT about using DPMI too, but that's sort of "hokey" don't you think? Small bucket into higher memory out of conventional memory iirc... right??

    APK

    P.S.=> I'd love to port a lot of the wares I put out online into 64-bit models is why - without having to change the language (porting PASCAL to C/C++ or VB is cake though I think (well, not really "cake" but, doable))... apk

  99. Heh - to "avoid confusion" small addendum by Anonymous Coward · · Score: 0

    I could have stated this using zero-based arrays as I should have:

    "First pointer is at location 1 in 'mellow' (m), the second 'double size' one is at 2 (twice it's size, (e))." - by Anonymous Coward on Wednesday June 15, @05:47PM (#36455760)

    By "at location 1" could have been said location zero instead (because they use zero based array positioning for 1st slot etc.).

    APK

    P.S.=> I think you get my point anyhow though... lol! apk

  100. Sloppy and Questionable by Anonymous Coward · · Score: 0

    Has anyone here actually tried to duplicate the tests? Surprisingly, it seems not.

    As checked in, it won't even compile for the Java version. There is a stray 'b' character in one of the files. Who has such bad processes that they can check in something that does not compile?

    Fixing that, it takes under a second to compile the Java version on my laptop. Since they report over 3 seconds, it seems like either my laptop blows away their equipment, or something is wrong. They do claim they ran on an old Pentium 4. Why would anyone do that?? Still, compiling the C version takes 1.7 seconds, twice as long as the Java compile.

    Then, running the test produces a stack overflow.

    Would anyone accept this kind of sloppiness at work?

    1. Re:Sloppy and Questionable by Anonymous Coward · · Score: 0

      Wow. In addition... I've compiled and run this on a reasonably modern server, with a reasonably recent JDK.

      The times I see:

              C++: 19.3 sec
              Java: 18.5 sec
              Java 'Pro': 11.2 sec

      What is going on? This isn't anything like the results in the paper, and it is on their code. Were they using Java 1.4 or something?

    2. Re:Sloppy and Questionable by smellotron · · Score: 1

      C++ is very sensitive to target architecture and compiler flags. That, and if they really did run everything on a Pentium 4, your tests will not reproduce theirs. Pentium 4 architecture was radically different from later Intel chips, AFAIK mostly due to a very deep pipeline.

    3. Re:Sloppy and Questionable by xxxyyyzzz · · Score: 1

      Sure - but there are a few things to note.

      1. The flags used are in their own Makefiles. Also, these days, it really is not very sensitive. Most decent compilers have very little variation in performance when twiddling with detailed optimization flags.

      2. The later Intel chips are enormously more important to anyone alive, and are more representative of real figures that will be observed, anyway.

      3. It still seems extremely notable that the Java versions - both simple and optimized - outperformed the C++ version.

      The last point is critical. It turns the whole article on its head. Instead of supporting all of the "of course, this is obvious" comments, it makes this a notable result. Even with very poor programming, the Java version outperforms the tuned C++ version on modern hardware.

      (And, definitely, the Java version was not written by a Java expert. It spews heap like crazy, uses Integer wrapped objects, uses generics where specialized primitive collections really need to be used, uses a custom set implementation that linearly scans the list on every insert, uses LinkedList where an ArrayDequeue or similar should be used, etc.)

      Any test like this wouldn't even be noted anywhere if it wasn't from Google, of course. It would be nice to have available the context which makes the results so radically different from anything realistic. (The only information we get is the "Pentium IV" bit, and a Java flag that does not actually exist.) I suspect that in addition to being run on antique hardware, it was also run with a JVM from 8 years ago.

  101. Right: which is WHY my "trick" should work by Anonymous Coward · · Score: 0

    Albeit on DYNAMIC strings too, not just static ones like Delphi 16 bit only had!

    (In fact? It's useful there, and on arrays work also (since strings are just really "character arrays" anyhow)).

    As 16-bit Turbo Pascal &/or BORLAND Pascal 16-bit didn't HAVE dynamic arrays though (Delphi does, but didn't really until Delphi 4 iirc thru Delphi 7 (the ones I like & for reasons already stated)).

    APK

    P.S.=> Think about this, positionally, using pointers:

    StringVar:= 'DELPHI';

    I send in a pointer to position #1 (zero). I send another but it's ALWAYS DOUBLE THE SIZE OF THE 1st POINTER.

    Thus, pointer 1 is on 'D', & pointer 2 (double size one) is on 'E'.

    I vector pointer 1 to position 2 now ('E'), the 2nd pointer is double its size, so it now is at position 4 ('P').

    I vector pointer 1 to position 3 now ('L'), the 2nd pointer is double its size, so it is now at position 6 ('i') in 'DELPHI'.

    I vector pointer 1 to position 4 now ('P'), the 2nd pointer will cause an abend/err (hence why I noted the 'errtrap' method, to prevent crash & gracefully exit... nice part is? In the err/abend you can send the value of pointer 1 @ midpoint now, to the return value from your function!

    This SHOULD work fine on ANY DYNAMICALLY ALLOCATED STRING TOO! Think about it.. gotta run to the store now!

    ... apk

  102. Re:C++ wins versus bytecode and interpreted langua by shutdown+-p+now · · Score: 1

    It's news in a sense that it shows that modern Java JIT compilers still can't optimize as efficiently as modern C++ AOT compilers (note that Java isn't really interpreted, at least not if you run that code a few thousand times to "warm up" before hand - it's all compiled to native code).

    Though, really, this perf difference has more to do with the fact that Java memory model is more high-level (in particular, it is verifiably memory safe), and that places much more of a burden on optimizer to implement it efficiently (e.g. escape analysis is needed to allocate objects on stack). In C++, you just give the programmer the ability to deal with memory as he sees fit, which leads to fast code when it's written correctly, and spectacular buffer overflow exploits when it's not.

  103. No, you are right. by VortexCortex · · Score: 1

    You jest, but what they've tested here is not a language, but a compiler and a runtime.

    As someone who writes compliers, I can tell you that the language is just syntax and form. The only "performance" test you can do on a damned language is to see how fast it is to code something. Here's a basic BASIC example.

    PRINT "Retarded Test is Retarded."

    C:
    puts( "Retarded Test is Retarded." );

    Java:
    System.out.println( "Retarded Test is Retarded." );

    C++
    std::cout << "Retarded Test is Retarded." << std::endl;

    Out of all of these languages, BASIC has the most "performance" in terms of simplicity, key presses, parsing, number of symbols / tokens, etc. (for this test).

    What's to keep all of these languages from to compiling (JIT for interpreted/VM languages) the above source codes down to the EXACT SAME sequence of machine code instructions?? NOTHING!!!!!!! Is BASIC now just as fast as C++ or Assembly Language for that matter?

    Point being: Languages have little to do with CPU performance of compiled / executing code -- They didn't even test the damn C++ code in more than one COMPILER, which is where your real optimization happens. Seriously, I wrote a language that's a subset of JavaScript that can optionally compile to machine code, and is faster than the exact same valid JavaScript code running in your web browser. Comparable code in G++ is slower, does this now make the JavaScript language faster than C++ ???

    Nothing to see here folks. They didn't test shit. If the two input programs perform the same tasks and produce the same output / results, but are simply described in two different languages, then what's to keep any sufficiently advanced optimizing compiler from generating the EXACT SAME machine code? NOTHING. Languages are how you describe to the complier what you want to do, it's the compiler / interpretor that is responsible for "CPU" performance.

  104. I shall attempt a rebuttal, to unmask your folly. by VortexCortex · · Score: 1
    If you want performance, platform independence, and less development time use a VM or JIT compiled language.

    Look at performance critical applications: High profile web sites, User Customizable Modules, Super Computer projects, data base integration, etc. Any time performance is high on the list people pick Java, Lua, Lisp, Pascal, PHP, Perl, Python and sometimes JavaScript. Platform independent (byte-code) deployment is the only feasible choice. The most expensive part of a project is its development time. Using a language that reduces this essential.

    One thing that VM byte-code interpreters and just in time (JIT) compilers give is the ability to tune the algorithm based on real execution profiling for multiple hardware platforms, without additional software rewrites. If you compile to machine code at some point you will run into language implementation decisions that the naive coder's control, and you will hit a wall because they could never imagine all future platforms.

    The computing field changes at an accelerating rate, now with ARM, x64, and even newer x86 chips, or even newer compilers on the same hardware, newly compiled code runs faster than the old binary you build 5 years ago. It is folly to produce software that is not portable to future hardware. This means more work on the part of the platform implementers, but the gain is significant because every program benefits when you upgrade the platform without having to spend development money on a per project basis. Centralized improvements give better distributed results.

    If other things like program execution speed are important (they rarely are, most frequent bottlenecks are IO latency -- even in video decoding) then use a native language interface to a compiled language like C (+ Assembly), which nearly all VM languages have support for. This allows you to take advantage of the ease of modification and make the best of programmer time, without sacrificing the ability to fine tune a small processor intensive section (for each targeted environment). Compiled languages may be faster once, but one size does not fit all -- And one set of machine code instructions is rarely fastest for all platforms, even when it's the same platform (x86 compiled for a Generic is slower than AMD or Intel specific targeted code).

  105. RTTI, throw, template, and small memory systems by tepples · · Score: 1
    C++ is the best choice in some but not all situations.

    RTTI and exceptions

    I can see how these are useful on PC- or smartphone-class hardware, but the support library adds substantial space overhead on embedded systems with 288 KiB of RAM and a 16.8 MHz CPU.

    in fact, C++ adds compile time code reduction through the template facility

    Templates are easy to inadvertently abuse once templated methods get instantiated once for each of several types. For example, sorting an array of each of several types may result in the sort routine getting copied for each type, compared to qsort() which uses the size of an element. What are the best practices to keep template bloat from happening?

    I guess a sufficiently determined programmer can hand compile Boost:Spirit to C code

    And in fact, this is how early C++ compilers worked, by outputting C code.

  106. Google is missing the point by Anonymous Coward · · Score: 0

    What I don't get is why Google is looking at all of these near-iron languages that have gotten so long in the tooth when newer, higher level interpreted web languages are achieving speeds similar to deeper level languages. Aren't most of their applications focused on the web these days? :P

    Admittedly, php, Ruby and the like (especially Ruby) are slow as molasses. But look at the new web interpreted language Lasso for an example of a new language which, through Java-like JIT (Just in time) compilation achieves amazing speed - not just of the final product, but also speed of development. There is more than just raw-iron speed when it comes to development...

    How old are these languages, anyway? Does everyone who programs in them have a white beard?