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

K

kebabklubben.emp

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
 
B

Ben Morrow

Quoth (e-mail address removed):
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
 
A

Alan Stewart

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
 
T

Tad McClellan

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
}
 
D

Dr.Ruud

Tad McClellan schreef:
kebabklubben.emp:

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);
'???';
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top