gpt4 book ai didi

GCC 中的优化

转载 作者:行者123 更新时间:2023-12-03 05:14:35 24 4
gpt4 key购买 nike

我有两个问题:

(1) 我在某处了解到 -O3 不推荐与 GCC 一起使用,因为

The -O3 optimization level may increase the speed of the resulting executable, but can also increase its size. Under some circumstances where these optimizations are not favorable, this option might actually make a program slower. in fact it should not be used system-wide with gcc 4.x. The behavior of gcc has changed significantly since version 3.x. In 3.x, -O3 has been shown to lead to marginally faster execution times over -O2, but this is no longer the case with gcc 4.x. Compiling all your packages with -O3 will result in larger binaries that require more memory, and will significantly increase the odds of compilation failure or unexpected program behavior (including errors). The downsides outweigh the benefits; remember the principle of diminishing returns. Using -O3 is not recommended for gcc 4.x.

假设我有一个工作站(Kubuntu9.04),有 128 GB 内存和 24 个内核,由许多用户共享,其中一些用户可能使用 60 GB 内存运行密集型程序。 -O2 对我来说是比 -O3 更好的选择吗?

(2) 我还了解到,当正在运行的程序意外崩溃时,任何调试信息都比没有好,因此建议使用 -g 来优化程序,无论是开发还是部署。但是当使用-ggdb3和-O2或-O3一起编译时,会减慢执行速度吗?假设我仍在使用同一个工作站。

最佳答案

  1. 唯一确定的方法是对使用 -O2 和 -O3 编译的应用程序进行基准测试。 -O3 还包含一些单独的优化选项,您可以单独打开和关闭。关于较大二进制文件的警告,请注意,仅比较使用 -O2 和 -O3 编译的可执行文件大小在这里并没有多大作用,因为这里最重要的是小型关键内部循环的大小。您确实必须进行基准测试。

  2. 这将导致可执行文件更大,但不会有任何明显的减慢。

关于GCC 中的优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1368746/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com