3

I have a operation in my project which takes around 2 minutes in debugging mode and less than a second in release mode. (If it matters, it's a function that writes a lot to a vector).

Obviously it's nearly impossible to use my application while in debugging mode due to the terrible performance that piece of code is causing.

So my question is: Is it possible to enable performance optimizations and disable debugging for a specific file or class? If not, any other ways to solve this problem?

KaareZ
  • 615
  • 2
  • 10
  • 22

1 Answers1

4

There are multiple aspects that affect performance:

Optimization (as you noted). You can specify optimization on a per file level using Properties -> C/C++ -> Optimization. You can also use #pragma optimize as described here: https://msdn.microsoft.com/en-us/library/chh3fb0k.aspx

Additional code that is only executed in the DEBUG configuration, like Checked Iterators; you can control them via _SECURE_SCL or _ITERATOR_DEBUG_LEVEL as described here: https://msdn.microsoft.com/en-us/library/aa985965.aspx

Also, you can unconditionally improve the performance of your code, for example, by reserving required space in your vector upfront to avoid reallocation.

Vlad Feinstein
  • 10,960
  • 1
  • 12
  • 27