Why is this code 100 times slower to debug?

I am using MSVC 2010.

I am trying to remove a duplicate (without saving any of them) from the list

Why is this code 100 times slower in debug mode?

Is there any other way to remove all equivalent objects and make them faster in debug mode?

At the moment, I cannot use debug at the moment. The process takes several minutes, and a few seconds in the release.

void SomeFunction() { std::list<Something> list; std::list<Something>::iterator it1; std::list<Something>::iterator it2; for (it1 = list.begin(); it1 != list.end(); it1++) { for (it2 = list.begin(); it2!=list.end(); it2++) { if (it1->SomeValue() == it2->SomeValue()) { if (it1 != it2) { list.erase(it1); list.erase(it2); it2 = list.begin(); it1 = it2++; } } } } } 
+8
c ++ visual-c ++ stl
source share
1 answer

In general, STL is very slow when debugging in Visual Studio due to iterator debugging support . You can speed this up significantly by setting _HAS_ITERATOR_DEBUGGING to 0.

+14
source share

All Articles