Thread: 2min in debug mode, 3sec in release!

  1. #1
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345

    Unhappy 2min in debug mode, 3sec in release!

    I'm using VC++.NET 2003 version, I have a rather complex program that, in some point, uses 2 nested for loops like this:
    Code:
    for (int i = 0; i < 2000; i++) {
    	if ( /* some condition */ ) { continue; }
    	for (int j = 0; j < 2000; j++) {
    		if ( /* some condition */ ) { continue; }
    
    		if ( /* some condition */ ) {
    			// do something
    		}
    	}
    }
    I can't optimize it any further.

    The problem is that this loop takes around 2 minutes to finish on my 2.4 GHz P4!
    I used the debugger and made the sure that this loop is delaying the whole program, nothing else.
    I tried to find something wrong in the conditions or the processing but everything was OK, finally I decided to switch to release mode and voila, it take only 3 seconds!
    I'm using release mode right now, it work fine, however, I can't use the debugger any more
    Any ideas how to speed things up in debug mode? cuz I really need the debugger.
    thx
    Last edited by glUser3f; 10-01-2003 at 05:34 PM.

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    you really need a loop to run 4 million times?
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    it's a part of my game engine, and yes, I do need it.
    You know games require a lot of processing power.

  4. #4
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    You might try debugging in the Release build. It is possible to build Release with debugging info and step through it the same as with the Debug build, but it will have the optimizations turned on so it should still go fast. I would only do this when necessary, since there are reasons that there are separate Debug and Release builds.

    Or you can try to set up situations for debugging where you don't have to loop so much. If you are attempting to fix a specific bug, many times you can debug something similar but smaller.

  5. #5
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    I looked for a way to add debug info to the release build but I didn't find anything, could you please tell me how?

  6. #6
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    I use VC++ 6.0, so it may be different, hopefully somebody else can verify or correct what I say. Go to Project->Settings and change the Settings For drop down to Release. Go to the C/C++ tab and the Category drop down should be General, then change the Debug info drop down to something else (I think Program Database). You'll probably have to rebuild all.

    I don't do this very often, so I'm not exactly sure of the steps, so like I said hopefully somebody else can chime in.

  7. #7
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    it worked, thx
    now I have a new problem, I'll create a new thread for it.

  8. #8
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    What, pray tell, do you need to do 4 million times?
    Away.

  9. #9
    Registered User glUser3f's Avatar
    Join Date
    Aug 2003
    Posts
    345
    I'm working on a BSP loader, I decided to speed up things by creating a list for each leaf that holds its visible leaves, most maps have more than 2000 leaves BTW

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > Any ideas how to speed things up in debug mode? cuz I really need the debugger.
    Yeah, you test it with a 20x20 section of the map rather than a 2000x2000 section.

    Debugging is all about providing you with the most amount of information about what is going on in your code. Release mode is about removing all the excess fluff to make the code as quick as possible.

    At the end, if you've done your debugging properly and written the code correctly, the actual size of the map should be irrelevant. If it worked well at 20x20, then it should work equally well at 2000x2000.

    If it doesn't, then you've missed something, so go back to 20x20 and reconsider what it is you're doing.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 09-16-2006, 07:11 PM
  2. Results in Debug and Release mode are different
    By jaro in forum C Programming
    Replies: 11
    Last Post: 05-27-2006, 11:08 AM
  3. release vs debug mode
    By bithub in forum Tech Board
    Replies: 2
    Last Post: 05-10-2006, 03:31 PM
  4. Release vs. Debug mode builds
    By earth_angel in forum C++ Programming
    Replies: 5
    Last Post: 11-10-2005, 04:41 PM
  5. Debug Mode Vs. Release Mode
    By incognito in forum Tech Board
    Replies: 5
    Last Post: 12-18-2003, 04:06 PM