AB
Size: a a a
AB
DS
SZ
A
A
A
use constant FOO => "foo bar baz"; my $x = FOO;
A
__PACKAGE__->FOO; $self->FOOи вот тогда всё плохо
A
$ perl const_bench.pl
Rate constant_arrow constant_object readonly constant
constant_arrow 2066450/s -- -0% -72% -72%
constant_object 2075800/s 0% -- -71% -72%
readonly 7275096/s 252% 250% -- -3%
constant 7494927/s 263% 261% 3% --
SZ
A
package READONLY {
use Readonly;
Readonly::Scalar our $FOO => "foo bar baz";
sub test {
my $x = $FOO;
my $y = $FOO;
my $z = $FOO;
my $res = $FOO . $FOO . $FOO;
}
}
package READONLY_FROM_PACKAGE {
sub test {
my $x = $READONLY::FOO;
my $y = $READONLY::FOO;
my $z = $READONLY::FOO;
my $res = $READONLY::FOO . $READONLY::FOO . $READONLY::FOO;
}
}
A
SZ
our $FOO = 5; Internals::SvREADONLY($FOO, 1)
?A
A
SZ
SZ
A
$ perl const_bench.pl
Rate constant_object constant_arrow readonly readonly_from_package constant
constant_object 2226950/s -- -2% -67% -68% -71%
constant_arrow 2274803/s 2% -- -67% -67% -71%
readonly 6813149/s 206% 200% -- -2% -13%
readonly_from_package 6924558/s 211% 204% 2% -- -11%
constant 7786455/s 250% 242% 14% 12% --
A
SZ
A