Remove slow debug prints with "ifdef" type of pre processor pragma.

Discussion in 'Perl Misc' started by kebabklubben.emp@gmail.com, Nov 12, 2007.

  1. Guest

    Hi!

    Is there a way to remove slow debug prints with some kind of "ifdef"
    type of pre processor pragma?

    They are to slow when I ran big batch jobs, but neat to have durinf
    development. Is there a way in Perl do define that debug prints are
    skipped without any loop overhead?

    Best Regards,
    Andreas Lundgren - Sweden
    , Nov 12, 2007
    #1
    1. Advertising

  2. Ben Morrow Guest

    Quoth :
    >
    > Is there a way to remove slow debug prints with some kind of "ifdef"
    > type of pre processor pragma?
    >
    > They are to slow when I ran big batch jobs, but neat to have durinf
    > development. Is there a way in Perl do define that debug prints are
    > skipped without any loop overhead?


    perldoc constant

    Ben
    Ben Morrow, Nov 12, 2007
    #2
    1. Advertising

  3. Alan Stewart Guest

    On Mon, 12 Nov 2007 06:00:01 -0800, wrote:

    >Hi!
    >
    >Is there a way to remove slow debug prints with some kind of "ifdef"
    >type of pre processor pragma?
    >
    >They are to slow when I ran big batch jobs, but neat to have durinf
    >development. Is there a way in Perl do define that debug prints are
    >skipped without any loop overhead?
    >
    >Best Regards,
    >Andreas Lundgren - Sweden


    use Smart::Comments;

    "Smart comments provide an easy way to insert debugging and tracking
    code into a program. They can report the value of a variable, track
    the progress of a loop, and verify that particular assertions are
    true.

    Best of all, when you're finished debugging, you don't have to remove
    them. Simply commenting out the use Smart::Comments line turns them
    back into regular comments."

    Alan
    Alan Stewart, Nov 12, 2007
    #3
  4. <> wrote:

    > Is there a way to remove slow debug prints with some kind of "ifdef"
    > type of pre processor pragma?



    No, but you can use constants, and let them be optimized away
    by the compiler.


    use constant DEBUG => 0;

    if ( DEBUG ) {
    # code here is optimized away
    }


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
    Tad McClellan, Nov 13, 2007
    #4
  5. Dr.Ruud Guest

    Tad McClellan schreef:
    > kebabklubben.emp:


    >> Is there a way to remove slow debug prints with some kind of "ifdef"
    >> type of pre processor pragma?

    >
    > No, but you can use constants, and let them be optimized away
    > by the compiler.
    >
    > use constant DEBUG => 0;
    >
    > if ( DEBUG ) {
    > # code here is optimized away
    > }


    .... and the surrounding if(){} structure as well.

    perl -MO=Deparse -e'
    use constant THE_END => 0;
    if (THE_END and my $s = "Goodbye World") {
    print "$s\n"
    }
    '
    use constant ('THE_END', 0);
    '???';

    --
    Affijn, Ruud

    "Gewoon is een tijger."
    Dr.Ruud, Nov 14, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Philips
    Replies:
    1
    Views:
    438
    Anthony Borla
    Feb 7, 2005
  2. Chris F Clark
    Replies:
    0
    Views:
    309
    Chris F Clark
    Aug 24, 2004
  3. brett
    Replies:
    1
    Views:
    295
    Rolf Magnus
    Feb 17, 2005
  4. brahatha
    Replies:
    1
    Views:
    653
  5. Srinivas Mudireddy
    Replies:
    3
    Views:
    1,674
    Peter Nilsson
    Oct 1, 2009
Loading...

Share This Page