当前位置:网站首页>O0 O1 O2 O3优化原理
O0 O1 O2 O3优化原理
2022-04-22 22:01:00 【心 灵 骇 客】
为了加快代码执行的效率,很多OJ平台都会自动开启O2优化。
在这里我们讲讲到底是怎么优化的。
O0优化
#pragma GCC optimize(0)
1、把变量分配到寄存器。
2、分析循环的会出现的各种情况,只保留一个退出循环的分支。
3、将没有用的代码删掉。
4、简化表达式和声明。
5、将用inline声明的内联函数变为函数调用。
O1优化
#pragma GCC optimize(1)
包含O0的各种优化功能,并增加了:
1、在变量赋值时,将数值直接赋给变量而不是给出变量的地址。
2、去掉没有用的变量和表达式。
3、去掉通用的表达式。
O2优化
#pragma GCC optimize(2)
包含O1的各种优化功能,并增加了:
1、去掉全局通用的子表达式。
2、去掉全局没有用的分配变量和表达式。
3、化解循环。
当只用-O选项时优化器自动进行-O2优化。
O3优化
#pragma GCC optimize(3)
包含O2的各种优化功能,并增加了:
1、去掉未调用的函数。
2、简化返回值未使用的函数。
3、将小函数进行内嵌调用。
4、对被调用的函数声明进行重新排序,以便被优化的调用方能够找到该函数。
5、完成文件级优化。
版权声明
本文为[心 灵 骇 客]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_62264287/article/details/124196394
边栏推荐
- How to make a successful open source project
- High end beer is losing young people
- 2.58-编写程序is-little-endian,当在小端法机器上编译和运行时返回1,在大端法机器上编译和运行时则返回0。这个程序应该可以运行在任何机器上,无论机器的字长是多少。
- SSM框架
- In the era of Internet of all things, how should smart home ecosystems such as Xiaomi, apple and Huawei be selected?
- Reinforcement learning (practice): dqn, double dqn, dueling dqn
- 都是做全屋智能的,Aqara和HomeKit到底有什么不同?
- Characteristics of Vickers Vickers proportional valve
- These two kinds of people can't do well in we media and can't make a lot of money all their life
- Metawork: please, this remote pairing programming is cool!
猜你喜欢

秒云助力中电科32所发布“基于拟态应用集成框架的SaaS云管理平台解决方案”

百思买Best Buy 网站EDI 测试流程

Buffer of Muduo source code analysis

Is it necessary to read the history of mathematics? We have neglected too much about mathematics education

51单片机proteus仿真 按键控制数码管数字显示

线性基(各种模板+例题)

中缀转后缀表达式(逆波兰式) 转 前缀表达式(波兰式)

TS经典类型体操:联合类型如何转为转交叉类型?需要知道三个点:分配律、逆变位置、逆变和协变

条件编译分析及使用
![[untitled]](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[untitled]
随机推荐
MySql内置函数
Borui data and F5 jointly build the full data chain DNA of financial technology from code to user
The 14th issue of HMS core discovery reviews the long article | enjoy the silky clip and release the creativity of the video
Secyun assisted the "SaaS cloud management platform solution based on pseudo application integration framework" released by CETC 32
如何做一款成功的开源项目
强化学习(实践):DQN,Double DQN,Dueling DQN
Sign up to open QKE container engine hosting version and container ecological Conference!
What is the working nature of Italian ATOS solenoid valve?
输入一行字符,单词之间用一个空格分隔,统计其中有多少个单词
Common commands of Linux
报名开启|QKE 容器引擎托管版暨容器生态发布会!
MySql--库的操作
7. Comparable to JMeter Net pressure measurement tool - crank Summary - what does crank bring
2021下半年软件设计师上午真题及答案解析
跨域问题及Umi-proxy代理解决跨域问题
Leetcode 04 Median of Two Sorted Arrays
Weekly Q & A highlights: is polardb-x fully compatible with MySQL?
【4.1】flink窗口算子的trigger触发器和Evictor清理器
Basic practice of C language (002-1)
snap安装repo问题