Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I had always assumed that perl's debugging hooks would only work if perl was run as perl -d, and would make your program horribly slow. It turns out that neither assumption is true. First, any code compiled while suitable $^P flags are set (see perldebguts), even when Perl is started without "-d", is debuggable. Second, when $DB::trace is 0 and minimal debugging flags are set, there seems to be no appreciable overhead. Specifically, with $^P = 0x303, which allows single-line stepping and gives nice caller information for evals and anonymous subs, debugging is essentially free.

To me, at least, this is seriously cool. I'm surprised this isn't more widely known or used.

Update: If you're wondering what prompted this, check out Sepia version 0.90 shortly. It only takes a couple hundred lines of ELisp + Perl to get a pretty decent GUD debugger in Emacs, and a minimal one would probably be less than 100. Once again, thank you Free Software!

Here are the benchmarks, with typical runtimes on my system:

sub fib { my $n = shift; if ($n < 2) { return $n; } else { return fib($n-1) + fib($n-2); } } __END__ $ time perl -le 'BEGIN { sub DB::DB {}; $^P=0x303 }; do "/tmp/fib.pl"; + print fib(28)' 317811 real 0m0.949s user 0m0.941s sys 0m0.006s $ time perl -le 'do "/tmp/fib.pl"; print fib(28)' 317811 real 0m0.924s user 0m0.918s sys 0m0.005s $ time perl -le 'BEGIN { sub DB::DB {}; $^P=0xfff }; do "/tmp/fib.pl"; + print fib(28)' 317811 real 0m1.719s user 0m1.712s sys 0m0.006s $ time perl -le 'BEGIN { sub DB::DB {}; $^P=0x303; $DB::trace=1 }; do +"/tmp/fib.pl"; print fib(28)' 317811 real 0m1.557s user 0m1.548s sys 0m0.006s

In reply to perl -d: faster and less scary than you think by educated_foo

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 studying the Monastery: (4)
As of 2024-04-23 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found