Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: debugging /logging help

by dchetlin (Friar)
on Dec 07, 2000 at 10:23 UTC ( #45447=note: print w/ replies, xml ) Need Help??


in reply to debugging /logging help

A brief comment on efficiency:

If you use constant subs instead of variables for toggling debugging, Perl is smart enough to compile them out of existence so when you go into production the debugging will have no adverse performance effects.

You can observe this in action using B::Deparse:

[~] $ perl -MO=Deparse -e'sub D(){0}print"foo"if D' sub D () { 0; } '???'; -e syntax OK [~] $ perl -MO=Deparse -e'sub D(){1}print"foo"if D' sub D () { 1; } print 'foo'; -e syntax OK

The `???' in the first example means that Perl has optimized out whatever used to be there. And you'll note the lack of a conditional in the second example, which was also optimized out. Perl is smart enough to realize that a subroutine with no parameters can be computed at compile time, and so replaces all calls to D() with its actual value (0 or 1 depending on the example). Then the peephole optimizer realizes that the print statements depend on the conditionals, and since the value of the conditionals is known, eliminates them and leaves either nothing, in the case of D() == 0, or just the bare print, in the case of D() == 1.

-dlc


Comment on Re: debugging /logging help
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://45447]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2014-11-26 06:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (163 votes), past polls