当前位置:网站首页>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循环内部进行调试。

边栏推荐
- Install the gold warehouse database of NPC
- Redis入门完整教程:客户端通信协议
- 攻防世界 misc 高手进阶区 a_good_idea
- Insert sort, select sort, bubble sort
- MP进阶操作: 时间操作, sql,querywapper,lambdaQueryWapper(条件构造器)快速筛选 枚举类
- 剑指Offer 68 - II. 二叉树的最近公共祖先
- Detailed explanation of heap sort code
- Breakpoint debugging under vs2019 c release
- Persistence mechanism of redis
- The overview and definition of clusters can be seen at a glance
猜你喜欢

共创软硬件协同生态:Graphcore IPU与百度飞桨的“联合提交”亮相MLPerf

Redis入门完整教程:发布订阅

Attack and defense world misc advanced area Hong

Editplus-- usage -- shortcut key / configuration / background color / font size

攻防世界 MISC 进阶区 hit-the-core

Redis getting started complete tutorial: publish and subscribe

Redis入门完整教程:事务与Lua

位运算符讲解

Redis入门完整教程:哈希说明
![[graph theory] topological sorting](/img/2c/238ab5813fb46a3f14d8de465b8999.png)
[graph theory] topological sorting
随机推荐
Erik baleog and Olaf, advanced area of misc in the attack and defense world
[odx Studio Edit pdx] - 0.2 - Comment comparer deux fichiers pdx / odx
How to send a reliable request before closing the page
Google Earth engine (GEE) -- take modis/006/mcd19a2 as an example to batch download the daily mean, maximum, minimum, standard deviation, statistical analysis of variance and CSV download of daily AOD
Redis入门完整教程:哈希说明
Google Earth engine (GEE) - tasks upgrade enables run all to download all images in task types with one click
Redis getting started complete tutorial: publish and subscribe
Attack and defense world misc advanced area ditf
The small program vant tab component solves the problem of too much text and incomplete display
[sword finger offer] questions 1-5
剑指Offer 68 - II. 二叉树的最近公共祖先
Co create a collaborative ecosystem of software and hardware: the "Joint submission" of graphcore IPU and Baidu PaddlePaddle appeared in mlperf
Explanation of bitwise operators
Attack and defense world misc advanced area Hong
LabVIEW中比较两个VI
攻防世界 MISC 进阶区 Erik-Baleog-and-Olaf
环境加密技术解析
Advanced area of attack and defense world misc 3-11
Redis入门完整教程:HyperLogLog
Is Huatai Securities a nationally recognized securities firm? Is it safe to open an account?