VS2008 C++发布模式比调试模式慢
我正在使用混合本机和托管 Visual C++,在本机中使用 STL。我有一个奇怪的问题。似乎当我在发布模式下编译软件并设置所有优化时,我的软件运行速度始终比调试模式慢。这里可能出了什么问题?
这些是我的调试命令行选项:
/Od /D "WIN32" /D "_DEBUG" /D "_UNICODE" /D "UNICODE" /FD /EHa /MDd /Fo"Debug\" /Fd"Debug\vc90.pdb ” /W3 /nologo /c /Zi /clr /TP /errorReport:prompt /FU “c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll” /FU “c:\Windows\Microsoft.NET \Framework\v2.0.50727\System.Data.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll" /FU "c:\Windows\Microsoft.NET\Framework \v2.0.50727\System.Windows.Forms.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.XML.dll"
这些是我的发布命令行选项:
/Oi /Ot / Oy /GT /GL /D "WIN32" /D "_SECURE_SCL=0" /D "_HAS_ITERATOR_DEBUGGING=0" /D "VC_EXTRALEAN" /D "_UNICODE" /D "UNICODE" /FD /EHa /MD /Fo"释放\ " /Fd"Release\vc90.pdb" /W3 /nologo /c /clr /TP /errorReport:prompt /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll" /FU "c :\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll" /FU "c:\ Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.XML.dll"
I am working with mixed Native and Managed Visual C++, using STL in the Native. I have a strange problem. It seems that when I compile my software in Release mode with all the optimizations set, my software consistently runs slower than in Debug mode. What could be wrong here?
These are my Debug command line options:
/Od /D "WIN32" /D "_DEBUG" /D "_UNICODE" /D "UNICODE" /FD /EHa /MDd /Fo"Debug\" /Fd"Debug\vc90.pdb" /W3 /nologo /c /Zi /clr /TP /errorReport:prompt /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.XML.dll"
These are my Release command line options:
/Oi /Ot /Oy /GT /GL /D "WIN32" /D "_SECURE_SCL=0" /D "_HAS_ITERATOR_DEBUGGING=0" /D "VC_EXTRALEAN" /D "_UNICODE" /D "UNICODE" /FD /EHa /MD /Fo"Release\" /Fd"Release\vc90.pdb" /W3 /nologo /c /clr /TP /errorReport:prompt /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll" /FU "c:\Windows\Microsoft.NET\Framework\v2.0.50727\System.XML.dll"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这完全不可能从命令行开关进行诊断,您必须使用分析器。
然而,相关的一件事是您使用 /clr 选项。除非您在代码中显式使用 #pragma Managed,否则所有内容都将转换为 IL,甚至是 STL 模板代码。这意味着您的优化设置没有任何影响,因为它们仅适用于生成的机器代码。然后,您将受到 JIT 编译器的优化影响。例如,当您连接了调试器时,默认情况下它不会优化。
That's utterly impossible to diagnose from the command line switches, you have to use a profiler.
One thing that's relevant however is you using the /clr option. Unless you explicitly use #pragma managed in your code, everything will be translated to IL, even the STL template code. Which means that your optimization settings have no effect whatsoever since they only apply to generated machine code. You are then subject to what the JIT compiler does for optimization. It will not optimize by default when you have a debugger attached for example.
尝试对发布版本进行分析,看看您是否注意到任何明显不正确的缓慢情况。如果需要,将其与调试版本的配置文件输出进行比较。
或者,如果调试版本主观上“足够快”,则只需发布它(尽管可能存在逆向工程影响)。
Try profiling the release version to see if you notice any obviously incorrect slowness. If needed, compare it to a profile output from the debug version.
Alternately if the debug version is subjectively "fast enough", just release that (although there might be reverse-engineering implications).