什么是“优化代码"?选项真的可以在Visual Studio中执行吗? [英] What does "Optimize Code" option really do in Visual Studio?

查看:94
本文介绍了什么是“优化代码"?选项真的可以在Visual Studio中执行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该选项的名称说明了什么,但是Visual Studio/编译器实际上是做什么的,真正的后果是什么?

Name of the option tells something but what Visual Studio/compiler really do and what are the real consequences?

如果您搜索Google,则可以找到此地址,但这并不是我真正想要的.我不知道真实的事情正在发生.例如,为什么循环会花费更少的时间,等等.

If you search google you can find this address, but that is not really I am looking for. I wonder the real things happening. For example why do the loops get less time, etc.

推荐答案

在没有优化的情况下,编译器会生成非常笨拙的代码-每个命令都以非常直接的方式进行编译,从而可以执行预期的操作.默认情况下,调试"版本的优化功能处于禁用状态,因为如果不进行优化,则生成的可执行文件将直接与源代码匹配.

Without optimizations the compiler produces very dumb code - each command is compiled in a very straightforward manner, so that it does the intended thing. The Debug builds have optimizations disabled by default, because without the optimizations the produced executable matches the source code in a straightforward manner.

一旦启用了优化功能,编译器就会应用许多不同的技术来使代码运行得更快,同时仍在执行相同的操作.在Visual C ++中,优化和未优化的版本之间最明显的区别是,变量值在优化的版本中会尽可能长地保存在寄存器中,而没有优化的变量值总是存储在内存中.这不仅影响代码速度,而且影响调试.这种优化的结果是,调试器在逐步执行代码时无法可靠地获取变量值.

Once you turn on the optimizations, the compiler applies many different techniques to make the code run faster while still doing the same thing. The most obvious difference between optimized and unoptimized builds in Visual C++ is the fact the variable values are kept in registers as long as possible in optimized builds, while without optimizations they are always stored into the memory. This affects not only the code speed, but it also affects debugging. As a result of this optimization the debugger cannot reliably obtain a variable value as you are stepping through the code.

/O中所述,编译器还应用了多种其他优化.选项(优化代码)MSDN文档.有关各种优化技术的一般说明,请参见 Wikipedia编译器优化文章.

There are multiple other optimizations applied by the compiler, as described in /O Options (Optimize Code) MSDN docs. For a general description of various optimizations techniques see Wikipedia Compiler Optimization article.

这篇关于什么是“优化代码"?选项真的可以在Visual Studio中执行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆