I'd like to leave some debugging functions in my code like this:
static final boolean DEBUG = true;
if (DEBUG) {
// do stuff here
}
Certain sections of my code are truly time-critical (and yes, I've
benchmarked it, and any delay is a problem). If I leave the debug code in
the app and set the static final DEBUG constant to false, will there be any
overhead? Is the compiler smart enough to omit the debug code altogether
when loading the class?
Andrey Kuznetsov - 19 Oct 2005 23:25 GMT
> I'd like to leave some debugging functions in my code like this:
>
[quoted text clipped - 9 lines]
> any overhead? Is the compiler smart enough to omit the debug code
> altogether when loading the class?
I read somethere that compiler is smart anough.
You can easy check it - just decompile class file.

Signature
Andrey Kuznetsov
http://uio.imagero.com Unified I/O for Java
http://reader.imagero.com Java image reader
http://jgui.imagero.com Java GUI components and utilities
Roedy Green - 19 Oct 2005 23:27 GMT
>Certain sections of my code are truly time-critical (and yes, I've
>benchmarked it, and any delay is a problem). If I leave the debug code in
>the app and set the static final DEBUG constant to false, will there be any
>overhead? Is the compiler smart enough to omit the debug code altogether
>when loading the class?
if DEBUG is a static final you will see no trace of the code inside
the ifs in your class files. You will see not trace of the ifs
either. This is why you must recompile the universe when you change
static finals.
You can reassure yourself this is true with a decompiler or
disassembler.
See http://mindprod.com/jgloss/decompiler.html
http://mindprod.com/jgloss/disassembler.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.