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?
// how it is now
// what I'd like
#define DEBUG_PRINT //
//#define DEBUG_PRINT qDebug
If I use #ifdef 's then the code is hard to read e.g.
qDebug("here I am");
qDebug("here I am again");
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")
#define qDebug(arg1, arg2, ..., argn) /* */
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(a)blu.org>
Boston Linux and Unix user group
PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9