I have a Managed VS2010 C++ project using toolset V10. What I couldn't figure out is, if I compile my project using Debug Configuration, the hash_map destructor is exceptionally slow. hash_map.clear() is slightly faster, but, just as painful.
Note: this cannot be reproduced on VS2015 + Win10. Most likely a VS2010 issue.
I look around the web, but, nothing explains what I am getting.
1) I checked the _NO_DEBUG_HEAP=1 environment setting. This doesn't work for me because I wasn't debugging through VS. I simply compile the code in debug configuration and run it without the debugger.
2) This is not about insertion a lot of data. The insertion is fine. This is about simply clearing the data from the hash_map.
3) I thought if I turn off C++ Exception under C++ Code Generation setting, I can fix the problem, which is not the case as well.
If I compile the code in Release Configuration, the destruction is instant. If I compile the code in Debug Configuration, the destruction is like 5 minutes or longer depends one how big the data is.
I am sure it is just some kind of C++ project setting I need to correct. Anyone know how to fix this?
To recap, my project is VS2010 Managed C++ (Mixed between C++ and Managed C# objects), toolset is v10. When I compile the code using Debug Configuration, it took 5 minutes to destroy the hash_map (slower than inserting the data itself). When I compile the code using Release Configuration, it is instant.
How do I fix this? Thank you.
Here is a full code on a new project I made using VS2010. It took me less than 5 seconds to insert the items. myMap.clear() takes 202 seconds. myMap destructor takes 280 seconds.
There is what I did.
1) Create new C++ Console App using VS2010...
2) Set Configuration Properties...
2.1) General > Common Language Runtime Support > No Support....
2.2) General > Character Set > Use Multi-Byte...
2.3) C/C++ > General > Common Language Runtime Support > Yes /clr...
2.4) C/C++ > General > Debug Information Format > Program Database /Zi...
2.5) C/C++ > Code Generation > Enable Minimal Rebuild > No /Gm-...
2.6) C/C++ > Code Generation > Enable C++ Exceptions > Yes with SEH /EHa...
Use Koby code below.
More Update:
This appears to be also dependent to the hardware? There is a big insertion performance difference between 30K and 40K. The insertion stuck at 32K for awhile and quickly insert rest of the items. When that happens, the map.clear() or destructor becomes massively slow.
The initial capacity may different on different machine? I am using a VM with 4GB of RAM on 64bits Windows7. The program is 32bits in Debug configuration.
Koby code result. Running compiled exe without VS2010.
Testing with 30K items:
TestClear()
Insertion: 0.163s
Clear: 0.075s
TestDestructor()
Insertion: 0.162s
Destruction: 4.262s
Testing with 40K items:
TestClear()
Insertion: 4.552s
Clear: 197.363s
TestDestructor()
Insertion: 4.49s
I gave up since destructor is much slower in 30K result..
Testing on VS2015 and 64bit Win10
Testing with 4M items:
TestClear()
Insertion: 8.988s
Clear: 0.878s
TestDestructor()
Insertion: 9.669s
Destruction: 0.869s
Conclusion: Something is most likely wrong with VS2010. I will mark this as resolved because VS2010 is way too old. I will try upgrade the entire solution to higher VS instead. Thank you Koby.