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

边栏推荐
- ETCD数据库源码分析——处理Entry记录简要流程
- 【室友用一局王者荣耀的时间学会了用BI报表数据处理】
- Redis démarrer le tutoriel complet: Pipeline
- D3.js+Three. JS data visualization 3D Earth JS special effect
- Redis入门完整教程:HyperLogLog
- Lost in the lock world of MySQL
- 图片懒加载的原理
- A complete tutorial for getting started with redis: Pipeline
- SHP data making 3dfiles white film
- Gnawing down the big bone - sorting (II)
猜你喜欢

C语言快速解决反转链表

Redis introduction complete tutorial: List explanation

JS card style countdown days

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

Redis introduction complete tutorial: detailed explanation of ordered collection

EditPlus--用法--快捷键/配置/背景色/字体大小

Attack and defense world misc advanced area can_ has_ stdio?

【二叉树】节点与其祖先之间的最大差值

攻防世界 MISC 进阶区 can_has_stdio?

攻防世界 MISC 高手进阶区 001 normal_png
随机推荐
Is Huatai Securities a nationally recognized securities firm? Is it safe to open an account?
A complete tutorial for getting started with redis: hyperloglog
Redis getting started complete tutorial: publish and subscribe
Google collab trample pit
攻防世界 MISC 高手进阶区 001 normal_png
Qt个人学习总结
Gnawing down the big bone - sorting (II)
Analog rocker controlled steering gear
Redis introduction complete tutorial: Collection details
Redis入门完整教程:Redis Shell
页面关闭前,如何发送一个可靠请求
Redis入门完整教程:事务与Lua
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
Photoshop批量给不同的图片添加不同的编号
Attack and defense world misc advanced grace-50
字体设计符号组合多功能微信小程序源码
OSEK标准ISO_17356汇总介绍
[Jianzhi offer] 6-10 questions
UML图记忆技巧
[try to hack] wide byte injection