20
votes

Im asking the experts here...

Does anybody have made some performance test about which compiler is the best for iPhone apps?

Since we have the choice between:

  • GCC 4.2
  • LLVM GCC 4.2
  • LLVM compiler 1.5

Im wondering which of the 3 offers the best performance...

I've done some quick test myself but haven't found much difference?

Which compiler are you using?

5
clang is made by apple, iphone is made by apple. sounds like llvm-clang should be it instead of llvm-gcc (in the long term at least) :)Johannes Schaub - litb
clang is not made by Apple, it's an LLVM project, and Apple doesn't make LLVM either.jer
@jer it's mainly made by apple, from what I see. it just happens to be open source and housed by the llvm project, so a lot of other people chime in and help. I wonder what the percentage is of apple and community is, though.Johannes Schaub - litb
@jer - While Apple did not create LLVM, Chris Lattner is now an employee of Apple and they've been driving LLVM like they do WebKit.Brad Larson
@jer they say at #llvm that >90% of clang is made by apple.Johannes Schaub - litb

5 Answers

11
votes

If you watch the WWDC 2010 session video 300, the Developer Tools State of the Union, you will see that Apple reports significant performance increases for applications built using the LLVM compiler over GCC (up to 60% faster in certain cases). There are additional improvements that can be made by using the Clang parser with the LLVM compiler. Watch Session 312 - "What's New in the LLVM Compiler" for more on this, as well as the sessions on LLVM from WWDC 2009, if you have them.

I saw a 20% speedup going from GCC to LLVM 1.5 in an informal benchmark within one of my applications, but it wasn't a rigorous test, so consider that only anecdotal evidence.

My recommendation is to use Clang + LLVM (LLVM Compiler 1.5) if you can for faster build times, more performant applications, and much better compiler errors. If you use C++ code or something else that the Clang parser cannot handle right now, use LLVM GCC to still get the performance benefits in your compiled application. Go to GCC only if that fails for some reason. It's a simple switch to hit in your build settings to gain even a small amount of extra performance for free in your end application.

LLVM Compiler 2.0, coming with Xcode 4, has full support for C++ and promises additional optimizations for compiled applications, along with more compile-time speedups. Xcode 4 even uses Clang as the syntax highlighting / code correction engine in the IDE. It's clear the direction that Apple is heading with their compilers.

3
votes

I do not know about performance for the iPhone, but in other benchmarks, Clang generally compiles faster but produces slower code than GCC. Clang also has better error messages than GCC. Thus, it might be best to use Clang in development, and switch to GCC for final production builds. If you choose such an approach, make sure you have a good QA cycle, or a build system that will also build and test the GCC build, so you don't get any nasty compiler related surprises at the end.

C++ support in Clang is a bit behind that of GCC (and more C++ code has been tested and tweaked for GCC's quirks than Clang's), so if you need to use a lot of C++, GCC might be a better option.

Really, you will need to choose the best compiler for your needs. Benchmarks, and other people's results, can give you an indication of what to consider, but every program is different, so the best approach would be to benchmark your own program on the different compilers, and see which works best for you.

2
votes

LLVM GCC 4.2 is what I use.

Clang does not handle C++ well enough, and it's very much a work in progress. It's a very promising toolkit, but it's just not stable enough for production at this time (in my experience).

Apple's definitely investing in Clang as their future compiler, but it is not a trivial project. Unfortunately, that puts many of us in a strange place, using one relatively old compiler and/or one very very new one (guess how many years it will before I can begin using features of c++0x in my codebases).

I've used the GCC frontend with LLVM backend with my codebases since it was available (at least, during testing). It's been publicly available for years, and is fairly stable. I've found the LLVM pass does produce smaller, faster executables in comparison to GCC alone (although I do more works targeting OS X than iOS). Frankly, I can't compile enough code with Clang alone to recommend it (plus, I have a lot of C++).

I've found the GCC+LLVM combo reliable. If reliability is your primary concern: begin with GCC, regularly test +LLVM in development, and regularly compile and test with Clang at each Clang release until you're satisfied with it. GCC+LLVM will usually be usable for today's production builds.

If speed is your concern, begin with GCC+LLVM, and test with Clang regularly (if that is an option for you -- it is not for me - too much c++).

Regarding Clang's parsing/lexing/generation: Clang aims to extremely standards compliant. They're doing well, but there are many features which are new or non-existent, which is why I suggest you be cautious, especially with C++.

I believe Apple's made their preferred compiler of the future obvious so... don't wait too long to test with Clang.

1
votes

I 'd like to introduce you this amazing article Compiler Options in Xcode - GCC or LLVM?

enter image description here

You won't wanna miss a single word, especially the section Which to choose ?

0
votes

With clang 1.5's C++ frontend is not the best, and I generally recommend against using it if you have to deal with any C++ code (this includes Objective-C++ code). In addition, I have experienced some weak linking problems when using clang, so to me, it's not ready for production if you have to deal with either of the above two cases.

That said, I have not noticed any real impact on performance between the two, though clang's errors and warnings are MUCH more useful than gcc's.

Food for thought.