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

边栏推荐
- The solution to the lack of pcntl extension under MAMP, fatal error: call to undefined function pcntl_ signal()
- 9 - class
- 剑指Offer 68 - II. 二叉树的最近公共祖先
- Three stage operations in the attack and defense drill of the blue team
- Gnawing down the big bone - sorting (II)
- Redis入门完整教程:Pipeline
- MYSQL架构——用户权限与管理
- Redis入门完整教程:客户端通信协议
- Redis入门完整教程:初识Redis
- P2181 diagonal and p1030 [noip2001 popularization group] arrange in order
猜你喜欢
![[machine learning] handwritten digit recognition](/img/26/cabdc5c92035181d82f6f809e6df0f.png)
[machine learning] handwritten digit recognition

Redis introduction complete tutorial: List explanation

Redis入门完整教程:Pipeline

Unity vscode emmylua configuration error resolution

A complete tutorial for getting started with redis: transactions and Lua

Redis入门完整教程:哈希说明

JS 3D explosive fragment image switching JS special effect

Sobel filter

Redis getting started complete tutorial: hash description

Redis introduction complete tutorial: slow query analysis
随机推荐
Redis getting started complete tutorial: Geo
Advanced area of attack and defense world misc 3-11
Feature scaling normalization
环境加密技术解析
P2181 对角线和P1030 [NOIP2001 普及组] 求先序排列
攻防世界 MISC 进阶区 Erik-Baleog-and-Olaf
Redis的持久化机制
The difference between Max and greatest in SQL
S32 Design Studio for ARM 2.2 快速入门
Sword finger offer 68 - I. nearest common ancestor of binary search tree
D3.js+Three. JS data visualization 3D Earth JS special effect
Record: how to scroll screenshots of web pages on Microsoft edge in win10 system?
LabVIEW中比较两个VI
Three stage operations in the attack and defense drill of the blue team
Principle of lazy loading of pictures
小程序vant tab组件解决文字过多显示不全的问题
【剑指Offer】6-10题
Unity Xiuxian mobile game | Lua dynamic sliding function (specific implementation of three source codes)
A complete tutorial for getting started with redis: Pipeline
Redis入门完整教程:慢查询分析