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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.