in reply to Re^2: Style: buried variables or double referencing?
in thread Style: buried variables or double referencing?
Depends. Readonly is slow, and not everyone can use Readonly::XS. The following code takes 48 seconds:
use Readonly; Readonly $C1 => 1; my $t0 = time(); my $a = 2; for (1 .. 10000000) { if ($a ++ == $C1) { ; } } print time() - $t0;
When this takes 4 second:
use constant C1 => 1; my $t0 = time(); my $a = 2; for (1 .. 10000000) { if ($a ++ == C1) { ; } } print time() - $t0;
If performance is important, use constant.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Style: buried variables or double referencing?
by tilly (Archbishop) on Aug 21, 2005 at 05:06 UTC | |
|
Re^4: Style: buried variables or double referencing?
by Anonymous Monk on Aug 22, 2005 at 09:58 UTC |