简体   繁体   English

MSVC2005 std :: _ Iterator_base ::调试时功能变慢

[英]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)复制了主要消费者

  • std::_Iterator_base::_Orphan_me 19.74 std :: _ Iterator_base :: _ Orphan_me 19.74
  • std::_Iterator_base::_Adopt 9.57 std :: _ Iterator_base :: _采用9.57
  • std::_Iterator_base::operator= 8.98 std :: _ Iterator_base :: operator = 8.98
  • std::_Iterator_base::~_Iterator_base 8.55 std :: _ Iterator_base ::〜_Iterator_base 8.55
  • std::_Iterator_base::_Iterator_base 7.37 std :: _ Iterator_base :: _ Iterator_base 7.37

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使其降低了释放速度,这些现在是我的主要探查器命中(对于该函数来说,这似乎很正常):

  • std::_Vector_const_iterator >::operator++ 29.79 std :: _ Vector_const_iterator> :: operator ++ 29.79
  • std::_Vector_const_iterator >::operator++ 26.26 std :: _ Vector_const_iterator> :: operator ++ 26.26
  • std::_Vector_const_iterator >::operator* 25.74 std :: _ Vector_const_iterator> :: operator * 25.74

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.

相关问题 使用Visual Studio 2005调试时调用函数? - invoking functions while debugging with Visual Studio 2005? 为什么迭代器调试在调试版本中会降低std :: unordered_map 200x的速度? - Why does iterator debugging slow std::unordered_map 200x in debug builds? MSVC 2010链接器错误2005与静态库中的std :: cout - MSVC 2010 linker error 2005 with std::cout in static library std::reverse_iterator 成员函数之间的区别:_Get_current() 和 base()? - Difference between std::reverse_iterator member functions: _Get_current() and base()? MSVC++ 17 std::copy 需要自定义迭代器的“操作符 -” - MSVC++ 17 std::copy expects “operator -” for custom iterator 标准::数组<int>迭代器可在 clang 但不是 MSVC 上转换为 int*? - std::array<int> iterator convertible to int* on clang but not MSVC? MSVC std::_Container_base12 在 _Myproxy 中有错误的数据 - MSVC std::_Container_base12 has wrong data in _Myproxy MSVC 2015 - 自定义迭代器的std :: for_each中的编译器错误(仅在DEBUG中时) - MSVC 2015 - compiler error in std::for_each for custom iterator (only when in DEBUG) 在迭代器中从std :: list中删除条目 - Remove an entry out of a std::list while iterator 存储在std :: map中的C ++基本迭代器 - C++ base iterator stored within std::map
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM