use strict; use warnings; use Benchmark qw( cmpthese ); use constant DEBUG => 0; our $N ||= -3; our $debug = 0; our $b = 100; cmpthese $N, { constant => q{ for( 1 .. 1000 ){ my $a = 10 * $b; $a = 10 * $b if DEBUG; } }, noconstant => q{ for( 1 .. 1000 ){ my $a = 10 * $b; } }, var => q{ our $debug; for( 1.. 1000 ){ my $a = 10 * $b; $a = 10 * $b if $debug; } }, }; __END__ C:\test>junk6 -N=-1 Rate var constant noconstant var 2222/s -- -19% -19% constant 2731/s 23% -- -1% noconstant 2745/s 24% 1% -- C:\test>junk6 -N=-3 Rate var constant noconstant var 2133/s -- -20% -25% constant 2662/s 25% -- -6% noconstant 2831/s 33% 6% -- C:\test>junk6 -N=-10 Rate var constant noconstant var 2172/s -- -18% -21% constant 2659/s 22% -- -3% noconstant 2746/s 26% 3% -- C:\test>junk6 -N=-20 Rate var constant noconstant var 2171/s -- -18% -21% constant 2632/s 21% -- -5% noconstant 2759/s 27% 5% --