Question about performance and perl code compilation:
I'm developing a web app (mod_perl), with copious logging conditionals sprinkled throughout the code. At the top of each module, I've got a set of constants defined with logging levels, and then a final constant "LOG_LEVEL":
use constant LOG_DEBUG => 70; use constant LOG_INFO => 60; use constant LOG_WARN => 50; use constant LOG_NONE => 0; . . # LOG_LEVEL is set to the desired LOG_* constant, to # determine the amount of logging detail use constant LOG_LEVEL => LOG_DEBUG; . . . # logging statements like this, throughout the code.... if ( LOG_LEVEL >= LOG_DEBUG ) { # do some logging here }
My question is, does the perl compiler throw out code (conditional statements) that have no chance of ever evaluating to true? i.e., in the example above, if I had set "use constant LOG_LEVEL => LOG_WARN", then that logging conditional would never run, so would perl actually evaluate it during runtime?
I'd like to think that when I'm ready for production, for performance I can just set my LOG_LEVEL to LOG_NONE, and none of those conditionals will ever be evaluated.
Lastly, I'm aware that using scalers (i.e., $LOG_LEVEL = $LOG_WARN) are perhaps slightly faster than constants, but if my assumption about perl throwing out this code is correct, then it shouldn't matter, right?
Thanks in advance for the help... something tells me this is a SFAQ (somewhat-frequent...) :)
cheers
MFN
In reply to using constants to trigger debug code by ManFromNeptune
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |