VisualStudio解决方案配置Debug和Release选项
前言
本文章基于VisualStudio2017編寫(xiě)
前兩天騰訊電話面試中面試官問(wèn)到既然平時(shí)有使用VS進(jìn)行項(xiàng)目調(diào)試,那介紹一下VS中Debug選項(xiàng)和Release選項(xiàng)有什么不同,我聽(tīng)到這問(wèn)題時(shí),知道Debug選項(xiàng)是我們平時(shí)使用VS要開(kāi)始運(yùn)行時(shí)點(diǎn)的那一個(gè)按鈕:
但是這個(gè)release是真的沒(méi)有注意到過(guò),我甚至都不確定面試官說(shuō)的英文單詞是什么。于是非常尷尬地,我跟面試官重復(fù)了好幾次 “啊?release?” “re–lea–se?” 這個(gè)問(wèn)題在我表示不理解后作罷…
今天在用VS調(diào)試數(shù)據(jù)挖掘的線性回歸作業(yè),這個(gè)每次運(yùn)行都要讀取25000*384個(gè)csv文件中的數(shù)據(jù),并且對(duì)這些數(shù)據(jù)進(jìn)行梯度下降算法計(jì)算,每次迭代都要遍歷這個(gè)規(guī)模的數(shù)據(jù)的程序,運(yùn)行一次下來(lái)就要半個(gè)多小時(shí)時(shí)間。某次調(diào)試時(shí),我注意到debug按鈕旁貌似有個(gè)下拉菜單,展開(kāi)后,前幾天我感覺(jué)云里霧里的”Release”靜靜躺在其中。
我先是想起前幾天面試被問(wèn)到的這個(gè)問(wèn)題后,google了Debug和Release的不同,簡(jiǎn)單地瀏覽到Debug是方便debug調(diào)試的,而Release是能優(yōu)化程序運(yùn)行的之后,出于試驗(yàn)?zāi)康倪x擇了Release選項(xiàng)運(yùn)行程序。
這個(gè)原本在Debug配置下要運(yùn)行半個(gè)小時(shí)的程序,使用Release配置,竟用了10S鐘就完成了運(yùn)行…
引用Jessie J在聽(tīng)到呼麥后的評(píng)論:“I’m absolutely shocked, but in a great way.”
這兩個(gè)選項(xiàng)是什么?
“Debug” and “Release” are actually just two labels for a whole slew of settings that can affect your build and debugging.
Debug選項(xiàng)和Release選項(xiàng)實(shí)際上是為一系列極多能影響程序的build和debugging的配置的標(biāo)簽/名字。(這兩個(gè)配置選項(xiàng)的不同貫穿整個(gè)窗口,不止是優(yōu)化配置不同)
當(dāng)你選擇了不同的運(yùn)行選項(xiàng),用來(lái)運(yùn)行你的程序的配置就會(huì)不同,由此程序運(yùn)行的效果就會(huì)受到影響。
它們有什么區(qū)別?
Debug選項(xiàng)稱為調(diào)試版本,顧名思義這個(gè)選項(xiàng)是調(diào)試的時(shí)候使用的。這個(gè)選項(xiàng)的配置中,所有代碼生成的優(yōu)化都是關(guān)閉的,于是我們觸發(fā)斷點(diǎn)后可以通過(guò)即時(shí)/局部變量窗口來(lái)觀察對(duì)應(yīng)的變量。
Program Debug Database files, which allow you to follow the execution of the program quite closely in the source during run-time.
All optimizations turned off, which allows you to inspect the value of variables and trace into functions that might otherwise have been optimized away or in-lined
A _DEBUG preprocessor definition that allows you to write code that acts differently in debug mode compared to release, for example to instrument ASSERTs that should only be used while debugging
Linking to libraries that have also been compiled with debugging options on, which are usually not deployed to actual customers (for reasons of size and security
Release選項(xiàng)稱為發(fā)布版本,這個(gè)選項(xiàng)的配置使得編譯器可以對(duì)我們的代碼進(jìn)行低等級(jí)的,復(fù)雜的優(yōu)化。優(yōu)化后代碼可能會(huì)”面目全非“,導(dǎo)致單步調(diào)試變得不可行,我們也無(wú)法在變量窗口中看到變量,因?yàn)槲覀円^察的變量可能被優(yōu)化了。并且發(fā)布版本不會(huì)生成.PDB文件(.PDB文件讓調(diào)試器能知匯編指令與代碼行數(shù)之間的對(duì)應(yīng)關(guān)系)
總之
需要調(diào)試程序時(shí),選用Debug選項(xiàng)
需要程序快速運(yùn)行時(shí),選用Release選項(xiàng)
總結(jié)
以上是生活随笔為你收集整理的VisualStudio解决方案配置Debug和Release选项的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: linux如何脚本监控tps,通过she
- 下一篇: 序列复杂度怎么看_《趣学算法》作者又一力