Visual C++-启用优化并浏览优化后的代码
Visual C++ - enable optimizations and browse the optimized code
如何在启用优化的情况下编译项目,并查看代码中更改了哪些优化。
例如:
我的原始代码:
printf("Test: %d",52);
for (int empty=0;i<100000;i++) {
//Nothing here
}
现在,当我用优化编译代码时,我想看到:(我想它会是这样的)
printf("Test: 52");
编译器不是
如何打开和关闭优化取决于编译器,因此您必须参考其文档。
在MSVS中,您可以从顶部工具栏中选择此选项-查找Debug
(未优化)与Release
(优化)。您可以通过使用调试器遍历代码来查看二进制代码,右键单击->showdissambly。
例如,您的代码生成:
如果不进行优化:
printf("Test: %d",52);
0097171E mov esi,esp
00971720 push 34h
00971722 push offset string "Test: %d" (9788C8h)
00971727 call dword ptr [__imp__printf (97C3E0h)]
0097172D add esp,8
00971730 cmp esi,esp
00971732 call @ILT+575(__RTC_CheckEsp) (971244h)
for (int i=0;i<100000;i++) {
00971737 mov dword ptr [i],0
0097173E jmp wmain+49h (971749h)
00971740 mov eax,dword ptr [i]
00971743 add eax,1
00971746 mov dword ptr [i],eax
00971749 cmp dword ptr [i],186A0h
00971750 jge wmain+54h (971754h)
//Nothing here
}
00971752 jmp wmain+40h (971740h)
通过优化:
printf("Test: %d",52);
013A1000 push 34h
013A1002 push offset string "Test: %d" (13A20F4h)
013A1007 call dword ptr [__imp__printf (13A209Ch)]
013A100D add esp,8
for (int i=0;i<100000;i++) {
//Nothing here
}
相关文章:
- 如何优化代码以返回最接近给定整数的数字,但给定列表中不存在?
- 需要消除这些"else if"并优化代码
- C/C++编译器是否会通过重用最近计算的函数结果来优化代码?
- 如何优化C 代码的以下片段 - 卷中的零交叉点
- C++按字符串调用函数,比较PHP的性能,如何在C++中优化代码
- 优化c++代码以添加两个作为字符串的数字
- x86 汇编和优化代码中的 for 循环
- 如何在gcc中设置模板功能的自动优化代码
- 优化代码/实现"for"循环而不是长"if - else if - else"
- 我的粒子群优化代码在 C++ 和 MATLAB 中生成不同的答案
- 优化代码以获取给定范围内可被整数整除的整数数
- if条件下两个字符串比较的优化代码
- Cuda Thrust - 如何使用sort_by_key、merge_by_key和reduce_by_key优化代码
- 如何优化代码中的参数
- 针对大量迭代优化代码
- 编译器在程序集中优化代码时会做什么?即O2标志
- 优化代码(康威的生命游戏)
- 用于 TSP 的 3 选项优化代码
- 如何使用 SSE 或 GLSL 优化"u[0]*v[0] + u[2]*v[2]"代码行
- 是否有任何情况将对象标记为 const 会导致更好的优化代码(使用优化编译时)