简体   繁体   English

iPhone GCC / LLVM GCC还是LLVM?

[英]iPhone GCC / LLVM GCC or LLVM?

Im asking the experts here... 我在这里问专家......

Does anybody have made some performance test about which compiler is the best for iPhone apps? 是否有人对哪些编译器最适合iPhone应用程序进行了一些性能测试?

Since we have the choice between: 既然我们可以选择:

  • GCC 4.2 GCC 4.2
  • LLVM GCC 4.2 LLVM GCC 4.2
  • LLVM compiler 1.5 LLVM编译器1.5

Im wondering which of the 3 offers the best performance... 我想知道3个中哪个提供最佳性能......

I've done some quick test myself but haven't found much difference? 我自己做了一些快速测试,但没有发现太大的区别?

Which compiler are you using? 你使用的是哪个编译器?

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). 如果您观看WWDC 2010会话视频 300(联盟的开发人员工具状态),您将看到Apple报告使用LLVM编译器构建的应用程序相对于GCC的性能显着提高(在某些情况下速度提高了60%)。 There are additional improvements that can be made by using the Clang parser with the LLVM compiler. 通过将Clang解析器与LLVM编译器一起使用,可以进行其他改进。 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. 观看会话312 - “LLVM编译器中的新功能”了解更多信息,以及WWDC 2009上的LLVM会话(如果有的话)。

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. 在我的一个应用程序中,我在非正式基准测试中看到了从GCC到LLVM 1.5的20%加速,但这不是一个严格的测试,所以请考虑只有轶事证据。

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. 我的建议是使用Clang + LLVM(LLVM编译器1.5),如果你可以更快的构建时间,更高性能的应用程序,以及更好的编译器错误。 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. 如果您使用C ++代码或Clang解析器目前无法处理的其他内容,请使用LLVM GCC仍然可以在编译的应用程序中获得性能优势。 Go to GCC only if that fails for some reason. 只有在出于某种原因失败时才转到GCC。 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的LLVM Compiler 2.0完全支持C ++,并承诺对编译应用程序进行额外的优化,以及更多的编译时加速。 Xcode 4 even uses Clang as the syntax highlighting / code correction engine in the IDE. Xcode 4甚至使用Clang作为IDE中的语法高亮/代码校正引擎。 It's clear the direction that Apple is heading with their compilers. 很明显,Apple正朝着编译器前进的方向发展。

I do not know about performance for the iPhone, but in other benchmarks , Clang generally compiles faster but produces slower code than GCC. 我不知道iPhone的性能,但在其他基准测试中 ,Clang通常编译速度更快,但产生的代码比GCC慢。 Clang also has better error messages than GCC. Clang还有比GCC更好的错误消息。 Thus, it might be best to use Clang in development, and switch to GCC for final production builds. 因此,最好在开发中使用Clang,并切换到GCC进行最终生产构建。 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. 如果您选择这样的方法,请确保您有一个良好的QA周期,或者构建系统也将构建和测试GCC构建,因此您最终不会得到任何令人讨厌的编译器相关的惊喜。

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. Clang中的C ++支持有点落后于GCC(并且更多的C ++代码已经针对GCC的怪癖进行了测试和调整,而不是Clang的),所以如果你需要使用大量的C ++,GCC可能是更好的选择。

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. 基准测试和其他人的结果可以告诉您要考虑的内容,但每个程序都是不同的,因此最好的方法是在不同的编译器上对您自己的程序进行基准测试,看看哪个最适合您。

LLVM GCC 4.2 is what I use. LLVM GCC 4.2就是我使用的。

Clang does not handle C++ well enough, and it's very much a work in progress. Clang不能很好地处理C ++,而且它正在进行中。 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. Apple肯定会投资Clang作为他们未来的编译器,但它不是一个简单的项目。 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). 不幸的是,这让我们很多人处于一个陌生的地方,使用一个相对较旧的编译器和/或一个非常非常新的编译器(猜测在我开始在我的代码库中使用c ++ 0x的功能之前会花多少年)。

I've used the GCC frontend with LLVM backend with my codebases since it was available (at least, during testing). 我已经使用带有LLVM后端的GCC前端和我的代码库,因为它可用(至少在测试期间)。 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). 我发现与单独的GCC相比,LLVM传递确实产生了更小,更快的可执行文件(尽管我做的工作比OS更多地针对OS X)。 Frankly, I can't compile enough code with Clang alone to recommend it (plus, I have a lot of C++). 坦率地说,我不能单独使用Clang来编译足够的代码来推荐它(另外,我有很多C ++)。

I've found the GCC+LLVM combo reliable. 我发现GCC + LLVM组合可靠。 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,并在每个Clang版本中定期编译和测试Clang,直到您对它感到满意为止。 GCC+LLVM will usually be usable for today's production builds. GCC + LLVM通常可用于今天的生产版本。

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++). 如果速度是您的关注点,请从GCC + LLVM开始,并定期使用Clang进行测试(如果这是一个选项 - 它不适合我 - 太多c ++)。

Regarding Clang's parsing/lexing/generation: Clang aims to extremely standards compliant. 关于Clang的解析/ lexing / generation:Clang的目标是极其符合标准。 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++. 他们做得很好,但有许多新功能或不存在的功能,这就是为什么我建议你保持谨慎,尤其是使用C ++。

I believe Apple's made their preferred compiler of the future obvious so... don't wait too long to test with Clang. 我相信Apple的未来首选编译器是明显的......所以不要等太长时间来测试Clang。

I 'd like to introduce you this amazing article Compiler Options in Xcode - GCC or LLVM? 我想在Xcode中介绍这个惊人的文章编译器选项 - GCC或LLVM?

在此输入图像描述

You won't wanna miss a single word, especially the section Which to choose ? 你不会想念一个单词,特别是哪个部分可供选择?

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). 使用clang 1.5的C ++前端并不是最好的,如果你必须处理任何C ++代码(这包括Objective-C ++代码),我通常建议不要使用它。 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. 另外,在使用clang时我遇到了一些弱连接问题,所以对我来说,如果你不得不处理上述两种情况中的任何一种,它还没有准备好生产。

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. 也就是说,我没有注意到两者之间对性能有任何实际影响,尽管clang的错误和警告比gcc更有用。

Food for thought. 值得深思。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM