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?

3
  • 1
    My first reaction would be to enable debug information in release mode, and debug that way. You do encounter a surprise now and again, but much more often than not, it's just fine. Commented Dec 16, 2015 at 16:55
  • You can also think about a mock object (#ifdef DEBUG_). Commented Dec 16, 2015 at 17:00
  • See stackoverflow.com/questions/12631609/… Commented Dec 16, 2015 at 18:20

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.