[英]MSVC2005 std::_Iterator_base:: functions slow while debugging
I'm profiling debug build c++ code in MSVC 2005 and certain code takes an extremely long time to execute (30+ seconds) compared to (1-2 seconds) in release. 我正在MSVC 2005中对调试版本的c ++代码进行性能分析,而与发布中的(1-2秒)相比,某些代码要花非常长的时间(30+秒)执行。
I've set _SECURE_SCL to 0 in the compiler options (/D _SECURE_SCL=0) and verified its set to zero in the source. 我已经在编译器选项(/ D _SECURE_SCL = 0)中将_SECURE_SCL设置为0,并在源中将其设置为零。
I've copied the top consumers from the profiler (AMD CodeAnalyst) 我已经从分析器(AMD CodeAnalyst)复制了主要消费者
Trying to debug code and having to wait 30+ seconds each time kinda sucks, is there something I'm missing here? 尝试调试代码,每次都要等30秒钟以上,我在这里缺少什么吗?
UPDATE: Wrapping #pragma optimize()
around the class method didn't do much but defining /D _HAS_ITERATOR_DEBUGGING=0
brought it down to release speed, these are now my top profiler hits (This seems normal for the function): 更新:在类方法周围包装
/D _HAS_ITERATOR_DEBUGGING=0
#pragma optimize()
并没有多大作用,但是定义/D _HAS_ITERATOR_DEBUGGING=0
使其降低了释放速度,这些现在是我的主要探查器命中(对于该函数来说,这似乎很正常):
3 functions, 60 instructions, Total: 2666 samples, 81.78% of shown samples, 2.76% of total session samples 3个功能,60条指令,总计:2666个样本,显示的样本的81.78%,会话总样本的2.76%
Thanks for the fast replies! 感谢您的快速回复!
You should also disable _HAS_ITERATOR_DEBUGGING
if you care about debug performance. 如果您关心调试性能,还应该禁用
_HAS_ITERATOR_DEBUGGING
。 When iterator debugging is enabled, a lot of bookkeeping is done to help you to detect bugs in your code where you use an invalidated iterator or fail to correctly manage container and iterator lifetimes. 启用迭代器调试后,将进行大量的簿记工作,以帮助您检测使用无效迭代器或无法正确管理容器和迭代器生存期的代码中的错误。
That said, a 30:1 performance difference between a checked debug build and an optimized release build sounds quite typical and reasonable. 也就是说,经过检查的调试版本与优化的发行版本之间30:1的性能差异听起来非常典型且合理。
Have a look at a few of the answers here: How to make MSVC debug builds run faster . 在这里看看一些答案: 如何使MSVC调试版本运行得更快 。
In addition to the _HAS_ITERATOR_DEBUGGING = 0
as mentioned by @James, it seems there's a neat trick toggling #pragma optimize("", off) / #pragma optimize("", on)
to disable optimisation for single functions/blocks of code etc. If you only want to debug inside a particular piece of code, disabling the optimisation for just that piece might be significantly faster than turning optimisations off globally. 除了
_HAS_ITERATOR_DEBUGGING = 0
提到的_HAS_ITERATOR_DEBUGGING = 0
之外,似乎还有一个巧妙的技巧可以切换#pragma optimize("", off) / #pragma optimize("", on)
Optimize #pragma optimize("", off) / #pragma optimize("", on)
Optimize #pragma optimize("", off) / #pragma optimize("", on)
以禁用对单个功能/代码块的优化等。如果只想在特定的代码段内进行调试,则仅对该段代码禁用优化可能比在全局范围内关闭优化要快得多。
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.