当前位置:网站首页>debug和release的区别
debug和release的区别
2022-07-04 22:37:00 【编程小段】
我们在使用Visual Studio编译cpp代码时,会有debug和release两种模式,那么这两种模式有什么区别呢?
先说结论:
一般在开发过程中,我们往往写的代码会有bug,为了便于调试,会选择debug模式进行编译,目的是不让编译器进行编译优化或者优化的少一些;但在开发完需要发布版本的时候,为了使生成的机器代码更快的运行,往往会选择release模式,这样编译器就会尽可能的帮我们进行编译优化。
下面来解释为什么
例如,我们写了一段代码,计算从0加到999的值,如果不使用编译器优化,那么生成的汇编代码如右半部分所示。
int main()
{
int res;
for(int i=0; i<1000; i++)
{
res += i;
}
return res;
}
但是,如果使用了-O3
级别的编译器优化(数字越大,优化级别越高),那么生成的汇编代码就变成了如下所示。因为编译器分析发现这段代码就是返回499500这个值,所以会优化成这样的汇编代码,显然运行速度快很多。但是假如我们需要在for循环内进行debug调试时,编译器会找不到这样的代码,因为汇编代码就没有for循环,所以不会调试。但是没有进行优化的代码就可以在for循环内部进行调试。
边栏推荐
- A complete tutorial for getting started with redis: getting to know redis for the first time
- 字体设计符号组合多功能微信小程序源码
- UML图记忆技巧
- EditPlus--用法--快捷键/配置/背景色/字体大小
- [Lua] Int64 support
- Create Ca and issue certificate through go language
- ETCD数据库源码分析——处理Entry记录简要流程
- Install the gold warehouse database of NPC
- How can enterprises cross the digital divide? In cloud native 2.0
- Unity Xiuxian mobile game | Lua dynamic sliding function (specific implementation of three source codes)
猜你喜欢
Redis getting started complete tutorial: Geo
SHP data making 3dfiles white film
攻防世界 MISC 进阶区 3-11
vim编辑器知识总结
Complete tutorial for getting started with redis: bitmaps
Redis introduction complete tutorial: slow query analysis
A complete tutorial for getting started with redis: redis shell
Redis的持久化机制
攻防世界 MISC 进阶区 Erik-Baleog-and-Olaf
集群的概述与定义,一看就会
随机推荐
字体设计符号组合多功能微信小程序源码
9 - class
啃下大骨头——排序(二)
Duplicate ADMAS part name
Redis getting started complete tutorial: hash description
LabVIEW中比较两个VI
Photoshop批量给不同的图片添加不同的编号
Redis démarrer le tutoriel complet: Pipeline
Analysis of environmental encryption technology
Redis introduction complete tutorial: Collection details
A complete tutorial for getting started with redis: Pipeline
Hit the core in the advanced area of misc in the attack and defense world
Redis入门完整教程:键管理
Redis入门完整教程:发布订阅
[roommate learned to use Bi report data processing in the time of King glory in one game]
[try to hack] wide byte injection
攻防世界 MISC 进阶区 3-11
Redis introduction complete tutorial: List explanation
攻防世界 misc 高手进阶区 a_good_idea
P2181 diagonal and p1030 [noip2001 popularization group] arrange in order