Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I am always qualifying the calls with an "if" to avoid the cost of a call/return pair. Is there anything else I can do to eliminate more of the performance overhead? A better method? BTW, I want the debug calls to be an execution time option. The program has a usage with a "-debug" option. Thanks!
Having a -debug option doesn't mean you need to do anything at execution time. You can check options in a BEGIN block and set a constant that controls whether debug statements will be optimized away or not:
$ cat deb.pl #!/usr/bin/perl use strict; use warnings; use Getopt::Long; my $FOO_DEBUG_MODE; BEGIN { GetOptions("debug", \$FOO_DEBUG_MODE) } use constant FOO_DEBUG_MODE => $FOO_DEBUG_MODE; print "debug statment\n" if FOO_DEBUG_MODE; print "done!\n";
Without the -debug option, the print and if are optimized away to be just an empty statement:
$ perl -MO=Deparse deb.pl use Getopt::Long; BEGIN {${^WARNING_BITS} = "UUUUUUUUUUUU"} use strict 'refs'; my $FOO_DEBUG_MODE; sub BEGIN { GetOptions 'debug', \$FOO_DEBUG_MODE; } use constant ('FOO_DEBUG_MODE', $FOO_DEBUG_MODE); '???'; print "done!\n"; deb.pl syntax OK
With -debug, the if is optimized away leaving just the debug call:
$ perl -MO=Deparse deb.pl -debug use Getopt::Long; BEGIN {${^WARNING_BITS} = "UUUUUUUUUUUU"} use strict 'refs'; my $FOO_DEBUG_MODE; sub BEGIN { GetOptions 'debug', \$FOO_DEBUG_MODE; } use constant ('FOO_DEBUG_MODE', $FOO_DEBUG_MODE); print "debug statment\n"; print "done!\n"; deb.pl syntax OK

In reply to Re: conditional debug call perf by ysth
in thread conditional debug call perf by greatdane

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-18 04:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found