views:

297

answers:

5

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?

A: 

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.

jer
This answer may address the weak-linking issues you are seeing with LLVM 1.5: http://stackoverflow.com/questions/3313786/ios-4-app-crashes-at-startup-on-ios-3-1-3-symbol-not-found-nsconcretestackblo/3314079#3314079
Brad Larson
Yeah I know, I didn't want to detract too much from the topic with solutions to problems the OP may not have experienced yet. :)
jer
+3  A: 

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.

Brian Campbell
+1  A: 

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.

Brad Larson
A: 

Which ever one i use will my app be approved by Apple? i am having some issues. If i use the GCC 4.2 it giving me some errors, but LLVM-GCC 4.2 everything works fine.

Jinah Adam
A: 

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.

Justin