Re: exectution speed and debugging output
On Apr 1, 3:48 pm, "Giff" <Giffn...@gmail.com> wrote:
Right now I am developing an application and I want to be able to
output on screen some variables. Anyway, I want to remove these output
operations when passing on the implementation of another function or
finiship up the program etc.. Still I whish to be able to have the
output again in case I will need to do some debugging in the future
(very likely!).
Now I pass to each function a bool parameter "show" and then, inside
the function:
if(show) output some stuff.
This sort of thing is more often handled by a global variable.
(It's one of the rare cases where a global variable is
appropriate.)
I suppose that this if-statement slows down the code a lot (and the
program MUST be fast), for instance because the compiler cannot
optimize not knowing the value of the show flag at runtime. Is that
correct?
No. The difference in speed is hardly noticeable.
What is the best way then to have this control over debugging output?
Should I use the preprocessor with a #define and then #ifdef /
#ifndef?
In general, I find some sort of logging class, invoked via
macros, to be preferable. Historically, I'd try to design the
macros so that they could be replaced with an empty string, if
performance issues required. In practice, they never did, and I
don't worry about it today.
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34