本文介绍了GCC中的优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个问题:
$ b $(1)我学到了-O3不推荐用于GCC的地方,因为

假设我有一台工作站(Kubuntu9.04),它有128 GB内存和24核心,并由许多用户共享,其中一些用户可能使用60 GB内存运行密集型程序。 (2)我还了解到,当一个正在运行的程序意外崩溃时,任何调试信息总比没有更好,所以,对于我来说,-O2是比-O3更好的选择吗?建议将-g用于开发和部署的优化程序。但是当用-ggdb3和-O2或-O3一起编译时,它会减慢执行速度吗?假设我仍然使用相同的工作站。 用-O2和-O3编译您的应用程序。此外还有一些-O3包含的单独优化选项,您可以单独打开和关闭。关于更大的二进制文件的警告,请注意,仅仅比较使用-O2和-O3编译的可执行文件大小在这里并不会有太大的好处,因为它是这里最重要的小型关键内部循环的大小。您必须进行基准测试。


  • 它会产生更大的可执行文件,但不应该有任何可衡量的减速。



  • I have two questions:

    (1) I learned somewhere that -O3 is not recommended with GCC, because

    Suppose I have a workstation (Kubuntu9.04) which has 128 GB of memory and 24 cores and is shared by many users, some of whom may run intensive programs using like 60 GB memory. Is -O2 a better choice for me than -O3?

    (2) I also learned that when a running program crashes unexpectedly, any debugging information is better than none, so the use of -g is recommended for optimized programs, both for development and deployment. But when compiled with -ggdb3 together with -O2 or -O3, will it slow down the speed of execution? Assume I am still using the same workstation.

    解决方案
    1. The only way to know for sure is to benchmark your application compiled with -O2 and -O3. Also there are some individual optimization options that -O3 includes and you can turn on and off individually. Concerning the warning about larger binaries, note that just comparing executable file sizes compiled with -O2 and -O3 will not do much good here, because it is the size of small critical internal loops that matters here the most. You really have to benchmark.

    2. It will result in a larger executable, but there shouldn't be any measurable slowdown.

    这篇关于GCC中的优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-19 21:08