Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

Overhead of if (DEBUG)

Thread view: 
Chris - 19 Oct 2005 21:40 GMT
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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.