• Create Account

## running 400% slower on Debug mode

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

9 replies to this topic

### #1そら .  Members

475
Like
0Likes
Like

Posted 07 November 2012 - 05:39 PM

Hi,

I was looking at the framerate I get between an executable (C++) compiled on Debug mode (with VisualStudio), and on Release mode. I expect Debug mode to run slower, but I'm getting ~8fps running in Debug mode versus ~30fps running in Release mode.

I've analyzed what functions the performance comes from, but, but... I really don't know how to tackle the issue, since it's Debug mode I'm not too worried about, but sometimes it's not easy to debug other stuff running so slow...

Obviously the code is the same on both, so... how could I improve the performance running in Debug mode?

Any ideas?..

Thanks!
"lots of shoulddas, coulddas, woulddas in the air, thinking about things they shouldda couldda wouldda donne, however all those shoulddas coulddas woulddas ran away when they saw the little did to come"

### #2SiCrane  Moderators

11526
Like
2Likes
Like

Posted 07 November 2012 - 06:01 PM

Unfortunately, the only way to make debug mode faster is to disable debugging helpers. You may want to consider using three configurations:debug mode, release mode and release with no optimizations. This gives you something that you can step through intuitively, but not encumbered performance-wise by things like extra fill patterns, but then you still have a build with those helpers when some goes screwy that you can't figure out without them.

3482
Like
1Likes
Like

Posted 07 November 2012 - 06:38 PM

Debug mode does tend to be slower than release but for many games with a modern CPU the graphics card is the bottleneck. You'll probably not only have issues in debug mode, but also on lower end CPUs. However running without the debugger attached may gain you some or more speed, depending on how much you use the heap. See http://www.altdevblogaday.com/2011/07/27/the-unexpected-performance-of-debug-builds/

The next thing to do to speed up the debug code is to change some compiler settings. See http://randomascii.wordpress.com/2011/07/22/visual-c-debug-buildsfast-checks-cause-5x-slowdowns/

You can also adjust your compiler settings on a per project, or per file basis which means you can leave optimizations off for easy debugging in the part of the code you're working on while having optimizations enabled elsewhere (e.g. debug game play code, with optimized rendering).

After that you need to profile the code, so you know where to optimize. You can do this on the debug code, but I'd suggest starting with the optimized code. You can get a decent free profiler at http://www.codersnotes.com/sleepy/

### #4Hodgman  Moderators

49411
Like
0Likes
Like

Posted 07 November 2012 - 07:34 PM

You may want to consider using three configurations:debug mode, release mode and release with no optimizations.

The 3 builds that I use are:
Debug - all assertions + no optimisation + debug symbols
Development - most assertions + mostly optimised + debug symbols
Shipping - no assertions + fully optimised + debug symbols

### #5wqking  Members

756
Like
0Likes
Like

Posted 07 November 2012 - 08:09 PM

Development - most assertions + mostly optimised + debug symbols

How do you have "most assertions"? You have different kinds of "assert" statements?

http://www.cpgf.org/
cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.
v1.5.5 was released. Now supports tween and timeline for ease animation.

### #6Washu  Senior Moderators

7714
Like
0Likes
Like

Posted 07 November 2012 - 08:23 PM

Development - most assertions + mostly optimised + debug symbols

How do you have "most assertions"? You have different kinds of "assert" statements?

Yes.
assert is just a macro, and you can define your own versions which can be optionally excluded based on preprocessor conditions. It can be useful to have a larger set of assertions for debug build, and a smaller set of them for a test build.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
ScapeCode - Blog | SlimDX

### #7Hodgman  Moderators

49411
Like
2Likes
Like

Posted 07 November 2012 - 08:40 PM

You can use something like this:
#define DEBUG_LEVEL 2 //this shouldn't be a #define; it should be set by the project config

#define DECLARE_DEBUG_MODULE( name, level ) const static bool dbg_##name = level <= DEBUG_LEVEL;
#define ASSERT( module, condition, message )	\
do { if( dbg_##module && !(condition) ) { AssertionFailure(__FILE__,__LINE__,message,#condition,#module); } } while(0)
void AssertionFailure( const char* file, int line, const char* message, const char* condition, const char* module )
{
//print text, show dialog, __debugbreak(), etc...
}

DECLARE_DEBUG_MODULE( FooBar, 2 ); // 2 == only debug, 1 == debug and development, 0 == all builds
void Test()
{
ASSERT( FooBar, 1==2, "test" );
}

### #8L. Spiro  Members

24837
Like
1Likes
Like

Posted 07 November 2012 - 08:58 PM

Note that you can enable certain optimizations for certain sections of code if you are sure those sections work and are causing you performance problems.
MSDN

L. Spiro

Edited by L. Spiro, 07 November 2012 - 09:22 PM.

### #9zfvesoljc  Members

543
Like
0Likes
Like

Posted 08 November 2012 - 03:19 AM

You can toggle debug settings (optimizations) per project or even per file in VS.

### #10tanzanite7  Members

1410
Like
0Likes
Like

Posted 12 November 2012 - 09:02 AM

Note that you can enable certain optimizations for certain sections of code if you are sure those sections work and are causing you performance problems.
MSDN

I can strongly recommend this. Except i use it in reverse - disable optimizations in sections i currently have problems with.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.