知乎上有篇详解   https://zhuanlan.zhihu.com/p/24402180 强烈推荐

C/C++的优化等级会对程序产生 不定性的影响,至于选择哪种优化等级必须从 现有的程序分析才行

可参考知乎上的讲解

原文

0     Minimum optimization. Turns off most optimizations.It gives the best possible debug view and the lowest level of optimization.

近乎不优化,用于调试代码。出现代码行不能设置断点可如此设置试试。

1          Restrictedoptimization. Removes unused inline functions and unused static functions.Turns off optimizations that seriously degrade the debug view. Ifused with --debug, this option gives a satisfactorydebug view with good code density.

部分优化。移除未调用的内联函数和静态函数,关闭debug窗口优化,此状态也能用于调试

2          Highoptimization. If used with --debug, the debug viewmight be less satisfactory because the mapping of object code tosource code is not always clear.

This is the default optimization level.

默认优化等级。如果处于debug状态,部分代码行将不能被调试,具体做了什么优化好像没说

3     Maximumoptimization. -O3 performs the same optimizationsas -O2 however the balance between space and timeoptimizations in the generated code is more heavily weighted towardsspace or time compared with -O2. That is:

-O3 -Otime aims to produce fastercode than -O2 -Otime, at the risk of increasingyour image size

-O3 -Ospace aims to produce smallercode than -O2 -Ospace, but performance might bedegraded.

In addition, -O3 performs extra optimizationsthat are more aggressive, such as:

High-levelscalar optimizations, including loop unrolling, for -O3 -Otime. Thiscan give significant performance benefits at a small code size cost,but at the risk of a longer build time.

More aggressive inlining and automatic inliningfor -O3 -Otime.

-O0
最少的优化,可以最大程度上配合产生代码调试信息,可以在任何代码行打断点,特别是死代码处。

-O1
有限的优化,去除无用的inline和无用的static函数、死代码消除等,在影响到调试信息的地方均不进行优化。在适当的代码体积和充分的调试之间平衡,代码编写阶段最常用的优化等级。

-O2
高度优化,调试信息不友好,有可能会修改代码和函数调用执行流程,自动对函数进行内联等。

-O3
最大程度优化,产生极少量的调试信息。会进行更多代码优化,例如循环展开,更激进的函数内联等。

另外,可以通过单独设置 --loop_optimization_level=option 来控制循环展开的优化等级。

原文链接:https://blog.csdn.net/liuqi3256797/java/article/details/90137350

最新文章

  1. 数据库性能优化之SQL语句优化
  2. kuangbin_UnionFind C (HDU 1213)
  3. 在类库中使用Session
  4. oracle表分区心得
  5. Spring处理id相同的bean
  6. 修改spfile导致oracle无法启动
  7. Swift - 做一个简单的无线U盘(手机端Http服务器搭建)
  8. Maven使用-利用Maven引入相关包(Struts2)
  9. Masonry 添加约束要注意顺序
  10. FORM级别和数据库级别的Trace
  11. 痞子衡嵌入式:ARM Cortex-M文件那些事(7)- 反汇编文件(.s/.lst/.dump)
  12. 第二章 基础查询 2-1 SQL语句基础
  13. java多线程 -- 创建线程的第三者方式 实现Callable接口
  14. Zabbix监控web,MySQL,TCP状态,Nginx
  15. 从零一起学Spring Boot之LayIM项目长成记(二) LayIM初体验
  16. SQL 创建自定义方法,匹配正则
  17. 第15届浙江省赛 D Sequence Swapping(dp)
  18. element开源框架
  19. The C programming language [book]
  20. python爬虫基础01-HTTP协议

热门文章

  1. 以图搜图(demo创建流程)
  2. linux升级系统内核
  3. java中overload与override的区别
  4. 【力扣】:N字型
  5. linux系统下命令行方式创建KVM虚拟机
  6. iOS开发之各机型屏幕大小与键盘高度整理
  7. Python全栈学习笔记---网络编程(三)
  8. drools规则的入门使用
  9. 用Nodemailer发个邮件不算难?
  10. C语言源文件如何编译为exe