I am making a lib that process statistics/odds It does a TON of conditional processing and makes extensive use of STL. I used to be able to process about 1200 sets of numbers / second. I added a bunch code and comments all over the place for debugging information out to the console. When running in debug it is EXTREMELY slow, which is acceptable. When running without the debug statements it is now at about 300 sets/second. (I added a bunch of complication and recursive functions which slowed it down). I had setup a bunch of if statements to see if I'm in debug mode or not so it doesn't write out to the console if not. By commenting out all the if statements in one recusive function gives me about 100 sets/second more. my question is this is there a way to define "//" to be replaced? e.g. // how it is now if(debug) qDebug("this"); // what I'd like #define DEBUG_PRINT // //#define DEBUG_PRINT qDebug DEBUG_PRINT("this"); If I use #ifdef 's then the code is hard to read e.g. for(x) { for(y) { for(z) { #ifdef DEBUG qDebug("here I am"); #endif somestatment(blah); andanotherone(blah); if(somehting) { #ifdef DEBUG qDebug("here I am again"); #endif conditional(blah); } } } } any help would be appreciated B-)
Brad Bourn wrote:
I am making a lib that process statistics/odds
It does a TON of conditional processing and makes extensive use of STL.
I used to be able to process about 1200 sets of numbers / second.
I added a bunch code and comments all over the place for debugging information out to the console. When running in debug it is EXTREMELY slow, which is acceptable. When running without the debug statements it is now at about 300 sets/second. (I added a bunch of complication and recursive functions which slowed it down). I had setup a bunch of if statements to see if I'm in debug mode or not so it doesn't write out to the console if not. By commenting out all the if statements in one recusive function gives me about 100 sets/second more.
my question is this
is there a way to define "//" to be replaced?
e.g.
// how it is now if(debug) qDebug("this");
// what I'd like
#define DEBUG_PRINT // //#define DEBUG_PRINT qDebug
DEBUG_PRINT("this");
If I use #ifdef 's then the code is hard to read e.g.
for(x) { for(y) { for(z) { #ifdef DEBUG qDebug("here I am"); #endif somestatment(blah); andanotherone(blah); if(somehting) { #ifdef DEBUG qDebug("here I am again"); #endif conditional(blah); } } } }
any help would be appreciated
B-)
What about just doing something like this: #DEFINE DEBUG_MODE 1 if(DEBUG_MODE){ //debug code here} and just change the define to 0 for release. Most compilers should see the statement can never be executed and remove it. -- -Chris Kwasneski Software Engineer Yuma Proving Grounds
On Thursday 24 February 2005 3:16 pm, Brad Bourn wrote:
I am making a lib that process statistics/odds
It does a TON of conditional processing and makes extensive use of STL.
I used to be able to process about 1200 sets of numbers / second.
I added a bunch code and comments all over the place for debugging information out to the console. When running in debug it is EXTREMELY slow, which is acceptable. When running without the debug statements it is now at about 300 sets/second. (I added a bunch of complication and recursive functions which slowed it down). I had setup a bunch of if statements to see if I'm in debug mode or not so it doesn't write out to the console if not. By commenting out all the if statements in one recusive function gives me about 100 sets/second more.
my question is this
is there a way to define "//" to be replaced?
e.g.
// how it is now if(debug) qDebug("this");
// what I'd like
#define DEBUG_PRINT // //#define DEBUG_PRINT qDebug
DEBUG_PRINT("this");
If I use #ifdef 's then the code is hard to read e.g.
for(x) { for(y) { for(z) { #ifdef DEBUG qDebug("here I am"); #endif somestatment(blah); andanotherone(blah); if(somehting) { #ifdef DEBUG qDebug("here I am again"); #endif conditional(blah); } } } } There are so many ways to do it. First, remember that gcc's default optimization is no optimization. Also, remember that when using recursion, you are using a lot of stack. And also remember that the STL uses a lot of memory. You need to be very careful that your destructors get called. Here is something quick (from a Cish point of view) #if defined DEBUG #define qDebug(arg1, arg2, ..., argn) \ fprintf(stderr, "%s, %s, %s, ... %s\n") #else #define qDebug(arg1, arg2, ..., argn) /* */ #endif
In this case, if DEBUG is defined, then you get qDebug if not you get an empty comment. Another way to do this is to define a debug class such as: DeBug << "....." << ....; The when not debugging you can have a non-debug class that is effectively empty. Make the constructors and member functions inline. -- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
participants (3)
-
Brad Bourn
-
Chris Kwasneski
-
Jerry Feldman