GCC:-O3和-Os之间的差异 [英] GCC: Difference between -O3 and -Os

查看:2601
本文介绍了GCC:-O3和-Os之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我非常熟悉GCC -O3标志,但它与-Os有什么不同,在这种情况下我们应该比其他更喜欢。

I am quite familiar with GCC -O3 flag, but how it differs from -Os, in which situation we should prefer one over other?

推荐答案

GCC文档说明了这些选项非常明确的作用。

The GCC documentation describes what these options do very explicitly.

-O3尝试极大地优化代码以提高性能。它包括所有的优化-O2包括,另外一些。

-O3 tries to optimize code very heavily for performance. It includes all of the optimizations -O2 includes, plus some more.

-Os,另一方面,指示GCC优化大小。它启用所有-O2优化,这不会增加可执行文件的大小,然后它也切换一些优化标志,以进一步减少可执行文件的大小。

-Os, on the other hand, instructs GCC to "optimize for size." It enables all -O2 optimizations which do not increase the size of the executable, and then it also toggles some optimization flags to further reduce executable size.

请注意,我故意有点含糊地与我的描述 - 阅读GCC文档,以更深入的讨论确切哪些标志启用优化级别。

Note that I've been deliberately a bit vague with my descriptions - read the GCC documentation for a more in-depth discussion of exactly which flags are enabled for either optimization level.

我相信-O *优化级别只是互相排斥,不同的优先级。 将它们混合并没有什么意义,因为两个级别将启用或者省略另一个有意分离或者启用的标志。如果你想混合和匹配(你可能实际上不想这样做,除非你有一个很好的理由想要一个特定的标志),你最好是阅读文档,混合和匹配的标志每个级别

I believe the -O* optimization levels are just that - mutually exclusive, distinct levels of optimization. It doesn't really make sense to mix them, since two levels will enable or leave out flags that the other one intentionally leaves out or enables (respectively). If you want to mix and match (you probably don't actually want to do this, unless you have a really good reason to want a specific set of flags), you are best off reading the documentation and mixing and matching the flags each level enables by hand.

我想我也会将这篇文章< a>来自Gentoo Linux Wiki,其中涉及关于为操作系统构建软件包的优化标志。显然不是所有这一切都适用,但它仍然包含一些有趣的信息 - 一个:

I think I'll also link this article from the Gentoo Linux Wiki, which talks about optimization flags as they relate to building the packages for the operating system. Obviously not all of this is applicable, but it still contains some interesting information - for one:


使用-O3编译不是一种保证的方式以提高性能,事实上在许多情况下可以减慢系统,由于较大的二进制和增加的内存使用。 -O3也被称为打破几个包。因此,不推荐使用-O3。

Compiling with -O3 is not a guaranteed way to improve performance, and in fact in many cases can slow down a system due to larger binaries and increased memory usage. -O3 is also known to break several packages. Therefore, using -O3 is not recommended.

根据文章,-O2在大多数时候 -O3,并且对于破坏的可执行输出使用更安全。

According to that article, -O2 is, most of the time, "as good as" -O3, and is safer to use, regarding broken executable output.

这篇关于GCC:-O3和-Os之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆