Slashdot Mirror


Comparing Linux C and C++ Compilers

ChaoticCoyote writes "I've posted a comparison of recent GCC versions (3.3, 3.4, and the coming 4.0) with Intel C++ 8.1, including several benchmarks and "state-of-the-product" reviews. The new article replaces an older piece I published in late 2002. This new comparison marks what I hope will be an ongoing series that tracks the quality of Linux compilers."

32 of 379 comments (clear)

  1. gcc! by dosius · · Score: 4, Insightful

    well, GCC has one thing going for it - it's open source - and that's why I'm sticking with it. XD

    FP?

    Moll.

    --
    What you hear in the ear, preach from the rooftop Matthew 10.27b
    1. Re:gcc! by antifoidulus · · Score: 4, Insightful

      Yeah but how important is ultra-high performance for you? If you are in charge of a multi-million dollar super computer, I would hope that you wouldn't say, "Well, I can get better performance out of this commerical compiler, but I disagree with commercial software, so I'll use open source"
      My view on the whole open-vs-closed debate is whatever gets the job done. There are a lot of open source tools that get the job done quite well, and I use those. But there are also occaisions where proprietary software gets what I need done quicker and easier, so I'll use that.

    2. Re:gcc! by E_elven · · Score: 1, Insightful

      Of course the test was run on an AMD 64, so Intel may not be showing its best.

      I personally use Icc for the compile-time diagnostics and warnings, which usually clarify the errors from GCC, and frequently show undetected ones.

      --
      Marxist evolution is just N generations away!
    3. Re:gcc! by Xabraxas · · Score: 4, Insightful
      Sorry but... ProPolice sucks.

      Why?

      Nobody cares about stack smashing protection anymore these days.

      OpenBSD

      Hardened Gentoo

      GCC 4.0 has libmudflap and -fmudflap for C and C++. While this isn't exactly the same as stack smashing protection, it is still very effective and much more efficient.

      Last time I checked GCC 4.0 wasn't stable.

      It's not entirely without reason that IBM still hasn't posted ProPolice for inclusion in the FSF GCC mainline. The patch against SUSE's hammer branch has been floating around literally for years, but they know really only very few people truely believe it makes a difference.

      That's crap. Propolice does exaclty what it is supposed to do. It doesn't protect against all stack smashing attacks but no one ever claimed that it did.

      --
      Time makes more converts than reason
    4. Re:gcc! by Anonymous Coward · · Score: 1, Insightful

      How many "ultra high performance" applications you see running on x86 hardware?

      Only clusters, which are pretty high-end as far as high-end goes. But I'd bet dollars to donuts that they use GCC with them.

      After all, they are all Linux clusters. And especially PowerPC-based clusters Apple's compiler of choice is.... GCC.

      There is a reason for:
      flexibility, portability, compatability > speed.

      It's not just idealism, it's cold hard reality.

      It's the same reasons that Unix is still dominate platform in high-performance and high end stuff, and VMS and it's contemporaries are now just history.

      Hell even NT/W2k were suppose to be "unix-killers" but they didn't make a dent in Unix's core market. They just grew along with the PC desktop.

      The closest anything else comes to "unix killing" is Linux... A Unix clone.

      Face it, GCC is a industry standard for a reason. It'll be around long after ICC and friends are long gone or completely rewriten.

    5. Re:gcc! by Sipos · · Score: 4, Insightful

      It seemed to be surprisingly fast in these benchmarks. Did you see the size of the icc binaries. I am not sure what the options for icc mean but I guess they must be doing loop unrolling/peeling and aligning functions to improve the cache useage. If you enable these on gcc you can gain a huge increase in performance (at the expense of larger code size). It may well be able to produce faster binaries than icc for the same size in many of the tests.

    6. Re:gcc! by hopethishelps · · Score: 1, Insightful
      If you are in charge of a multi-million dollar super computer, I would hope that you wouldn't say, "Well, I can get better performance out of this commerical compiler, but I disagree with commercial software, so I'll use open source"

      A multi-million dollar supercomputer will not use 32-bit Intel processors, so you can't choose the Intel compiler anyway.

      For some other architecture, it's much less likely that a proprietary compiler will do better than the Gnu compilers. Most compilers have bugs. The Gnu compilers are well tested, as a result of their wide use over many years.

    7. Re:gcc! by bit01 · · Score: 4, Insightful

      "is $x > $y?"

      This is only true if you include all costs and benefits, not just the sticker price.

      Commercial vendors would love for customers to consider only the sticker price without taking into account the many hidden and recurring costs in most commercial software solutions.

      ---

      Astroturfers are scum.

  2. Performance isn't everything. by acceleriter · · Score: 5, Insightful

    Even if the Intel compiler is faster, it's best not to get in the habit of becoming locked into any proprietary platform. How likely is it that features on which one could come to depend will be kept available on free platforms, much less future processors not made or controlled by Intel?

    --

    CEE5210S The signal SIGHUP was received.

    1. Re:Performance isn't everything. by Guidlib · · Score: 2, Insightful

      I'm certain that if there was some quirk that seperated ICC from other compilers that you just loved abusing, that it still wouldn't be terribly hard to make the few changes required to move to another compiler down the track. That's the beauty of using a language like C. So long as you conform to the standards in your code, you should be fine wherever you go. It seems almost like scaremongering to make the suggestion in the parent post.

    2. Re:Performance isn't everything. by Anonymous Coward · · Score: 2, Insightful

      So when the purveyors of proprietary software engage in FUD against Free Software, that's marketing, but when OSS folks point out the drawbacks of imprisoned software, that's "scaremongering?"

    3. Re:Performance isn't everything. by doomdog · · Score: 2, Insightful

      How is using an Intel compiler locking you into a proprietary platform? Well-written code can be run through any compiler -- your main cost in switching compilers is figuring out the correct command-line switches, since they're all different...

    4. Re:Performance isn't everything. by Screaming+Lunatic · · Score: 5, Insightful
      Even if the Intel compiler is faster, it's best not to get in the habit of becoming locked into any proprietary platform.

      That is why it is important to compile your code using multiple compilers. Prefer to write code to the C/C++ standards rather than to a particular compiler's idiosyncracies, GCC included. Different compilers also emit different warnings, helping one find bugs sooner.

    5. Re:Performance isn't everything. by psetzer · · Score: 2, Insightful
      In any complex system, I'd doubt that even the gods could work on it. Some days to me, it seems that programming isn't a science, but a random walk. Some changes screw things up, and the program won't even run after they're implemented. Others make the whole program work quicker and more efficiently. What we do is get rid of the bad changes and add the good ones. Open source means in the long run that there will be more changes, but thankfully, if the people working on it care about the end product, then the program will get better quickly since the good changes will be kept and the bad ones culled.

      No matter how good you think you are, and you may be one of the best, for all I know, compile time optimizations are often truly hairy, and sometimes the implementer doesn't even understand why they work. There's an old trick about how to add two 64-bit numbers in a computer with 32-bit registers in only four instructions. You can tell it to anyone, but the important thing is 'do they understand it?' If not then it's of little to no use in a properly written program. Otherwise, it's a neat little assembly trick taking advantage of the fact that a fairly complex algorithm for the carry bit can be broken down into one instruction.

      Algorithms used to speed compiled code are much more complex than that one instruction. Changing them significantly without understanding them at all is stupid. You are lucky if it breaks cleanly. Otherwise, your fix may be around to haunt you for years to come.

      --
      "Anyone who attempts to generate random numbers by deterministic means is living in a state of sin." -- John von Neumann
    6. Re:Performance isn't everything. by smcdow · · Score: 3, Insightful

      Prefer to write code to the C/C++ standards rather than to a particular compiler's idiosyncracies, GCC included.

      Nonsense. GCC has way too many extremely useful "idiosyncracies" to abandon. If you don't know what they are, then you aren't paying attention.

      Better that other compiler makers mimic GCC's behavior. Better still is for the standards groups to adopt GCC as the reference standard for C and C++ compilers.

      --
      In the course of every project, it will become necessary to shoot the scientists and begin production.
  3. C++ compile times? by tetromino · · Score: 2, Insightful

    One of the main reasons I was looking forward to the new GCC versions was faster compile times for C++. Yet it seems that for povray (the only c++ source in the benchmark), the compile times consistently get worse with newer versions of gcc. Does no-one care about people who actually compile kde?

  4. Re:Not a lot of selection for Linux compilers, eh? by tomstdenis · · Score: 5, Insightful

    Actually there are. LCC and TinyC come to mind. They're not used much in production [well LCC was reborn as LCC-Win32 for a while] but really GCC is the better choice.

    The problem with the "good old days" was that as my friend Dave Dunfield said once "C compilers are a dime a dozen".

    Just because you had a dozen C compilers for your 8086 doesn't mean you were better off. In fact most compilers for the 86 were crap [e.g. smallC, byteC, Zortech, paradise, etc...]. In fact the only half-way decent 86 compilers I recall are Turbo C [v3.01 was ok] and Micro-C [by Dave Dunfield so maybe I'm a bit biased there...].

    Note I'm not saying more compilers is bad. The problem is like any field "new" doesn't imply better. You have to tackle problems and answer them.

    For instance, GCC is rather large and can be slow/memhog on some files [C++ in particular]. A viable competitor for Linux would be one which optimizes decently while not being such a hog. It could pitch in when you can't build a file [say from VisualBoyAdvance which requires ~1GB of ram to build with GCC 3.4.2]...

    For the most part though, contributing to GCC makes more sense than writing your own compiler. First off, GCC is a "standard". So you're likely to get a huge audience that way. Second, GCC is already well established. It's a very good suite of tools and frankly hard to compete with. Third, you'll save a lot of time.

    For all intents and purposes you could change your argument to why do "linux" boxes only run the Linux kernel? I mean for all intents and purposes you could write your own kernel that was interoperable and use instead. For the same reason why contributing to GCC is a good idea so is contributing to the kernel [instead of writing your own] is a good idea.

    One last caveat before I send this post. I do agree though that writing such said tools [kernels or compilers in this case] are a good idea for educational purposes. It means a lot to know how to write a functional [and ideally half-way decent] compiler even if it only targets one platform and covers only part of a language. :-)

    phew...

    Tom

    --
    Someday, I'll have a real sig.
  5. illogical hostility? by Anonymous Coward · · Score: 1, Insightful

    Why all the comments that are vehemently pro-gcc? It reeks of a defensive posture when none is necessary. The man is trying to conduct a semi-scientific test. Isn't /. about science and truth and news for nerds that transcends the tripe in the mainstream media? If so, why the instant hostility?

    1. Re:illogical hostility? by ChaoticCoyote · · Score: 4, Insightful

      The hostility mystifies me. I'm a semi-active participant in the GCC mailing list, and the people who work on GCC are very helpful, open, and communicative. Some even thank me for my QA efforts.

      I don't see that my article is negative about GCC; in fact, I'm very clear that Intel's compiler isn't a replacement for GCC, and that GCC is a fine product. Maybe the complainers can't read?

  6. Re:Not a lot of selection for Linux compilers, eh? by Waffle+Iron · · Score: 2, Insightful
    You know, it seems there were far more compilers available for DOS and OS/2 than are available for Linux.

    That's most likely because the market for compilers has become more mature. There are usually fewer players left in a mature market than in a new one. It doesn't necessarily have anything to do with open vs. closed source.

  7. Re:apples and oranges by MonsterChicharo · · Score: 2, Insightful

    Unless you are targeting for binary compatibility among different architectures, the question is somewhat meningless. If you need to compile from the source, you may very well use a faster tool for the job; it can be Intel for Pentiums, and GCC for the rest.

    Granted, if you want to deliver a binary that runs on other platforms (by means of emulation or whatever) you better stick to GCC. Now, how many times do you need this?

    I believe the author of the article himself is stating that in the end you should be using the best tool for the job. So there.

  8. Re:This guy must be a nerd... by ChaoticCoyote · · Score: 3, Insightful

    Wolfram has some interesting points, but I think his ego has gotten in the way of good science. With his "New Kind of Science", Wolfram hasn't really "invented" anything; he's mostly implying meaning where it may or may not exist.

    On the other hand, I do believe that higher order derives from basic, simple, underlying processes that combine in great complexity. Turning that supposition into real science is something I hope to see happen in the next century.

  9. Are these tests even a valid measure? by skids · · Score: 2, Insightful

    Seems to me, you don't test the speed of a compiler on number crunching programs -- they are likely to have hand optimizations in them, and can benefit from hand optimization a lot more, so the compiler isn't as important in these applications since if you want real speed you write a core in asm.

    He should have tested code that contains a lot of tangled up complex loops switches and jumps. Like libperlre's parsing and execution speeds. That and some really horribly over-abstracted C++ code where 15 classes are used just to add two numbers together.

    (Perhaps the best test would be to compile a second copy of one version of gcc, and see how fast that can compile itself afterwards.)

  10. Re:Binary size by Xabraxas · · Score: 3, Insightful
    Yeah... and faster code most of the time, too, in spite of it. Memory is cheap these days (512M DDR400 = $73, 80G HDD = $50).

    Who cares about memory when hard drives are so slow? Reading from laptop HDs is especially painful and binary size does come into play.

    --
    Time makes more converts than reason
  11. Re:Binary size by Jthon · · Score: 2, Insightful

    Maybe, or by expanding the loop you just induce a bunch of cache misses which hurt performance more than the couple extra instructions to check a loop variable. In today's world memory is an order of magnitude slower than today's processors. By not unwinding the loop you get the benefit of the temporal locality. Of course the n copies of the loop may be fetched in one memory access. It all comes down to how many blocks are fetched by the cache for a miss, vs size of the unwound loop. If all n copies are fetched in a miss you win. If it takes n memory accesses instead of 1, you lose.

  12. Comparing _GNU_ C and C++ Compilers by latroM · · Score: 1, Insightful

    Those are GNU's compilers, not linux's. Why do you take all the credits from GNU which was the oríginal developer of the system? By calling the whole OS Linux, people who hear it first time think that Linus started it all with his kernel and there wasn't anything before that. Please, GNU/Linux and GNU's compilers.

  13. The real fun will begin when it outclasses GCC by Anonymous Coward · · Score: 1, Insightful

    Politics is holding GCC back once again ... FSF better pray LLVM doesnt get critical mass, or it will be EGCS all over again.

  14. Re:I don't get it... by strider44 · · Score: 2, Insightful

    So let me get this straight. You are attacking the writer for saying that that is a typo instead of a mistake? You, sir, are pedantic.

    But let me for a second play your game.

    Technically, by dictionary, a typo is "An error while inputting text via keyboard, made despite the fact that the user knows exactly what to type in. This usually results from the operator's inexperience at keyboarding, rushing, not paying attention, or carelessness."
    This means that should you accidentely type something totally different by habit or just thinking of something else, this will also classify as a typo under the definition of the world, for example typing "Gentoo AMD64" instead of "Gentoo x86" because he was copying the same format as above.

    Unfortunately you have just assumed that he made a mistake, that he literally thought that he had the AMD64 version installed on his computer, and thought "I knew there was something wrong with that", or he thought that Pentiums were a special class of Athalon 64. That would be classed as a mistake.

    Don't you know what they say about assuming: "don't assume or you'll make an arsehole out of yourself", or something like that. I say similar things about being pedantic as well.

  15. Re:Interesting image. by ChaoticCoyote · · Score: 2, Insightful
    Cheesy passive-agressive self deprecation comedy mixed with a "slip it to 'em that I probably had sex at least once" tangent? Thank god I didn't read your article.

    Sounds like jealousy to me... ;)

  16. Re:Binary size by IamTheRealMike · · Score: 2, Insightful
    Memory may be cheap but the increased performance gained from optimizing for code size isn't negligable.

    In particular small code can make apps start faster, and the whole computer feel more responsive. The day computers never swap and disk I/O isn't a bottleneck will be the day we can ignore code size in compiler benchmarks.

  17. Re:I am dissapointed in Intel by Anonymous Coward · · Score: 1, Insightful

    GCC only sucks under Windows for x86, at least in my experience.

    This is going to be an unpopular comment. But the problem isn't that GCC sucks, it's that MSVC is very good. GCC produces similar results on all x86 platforms. MSVC produces faster code on Windows. That is, the Microsoft product is simply better than the GNU product.

    Posted anonymously for reasons that should be obvious...

  18. Re:What about documentation to write new front end by ctid · · Score: 2, Insightful

    If you don't want to mess with back-ends etc, why not get your program to spit out C code? Then compile that with gcc. I think that SmallEiffel started out this way.

    --
    Reality is defined by the maddest person in the room