Subject: | Immense speed regression when used over same class |
I know this is an esoteric case, but nevertheless it can happen in the
wild. I also am not including any patches as I can not see how this is
even possible (parent.pm is rather simple...)
use strictures 1;
use Benchmark qw/cmpthese/;
require parent;
require base;
{
package Bench::Base;
sub foo { 1 };
}
my $c;
my $sub_iter = 100;
cmpthese (-1 => {
use_base => sub {
$c++;
for (1..$sub_iter) {
my $class = "Bench::Bas::Sub_${c}::SubSub${_}";
eval "package $class; use base 'Bench::Base'";
die unless $class->foo;
}
},
use_base_same_class => sub {
$c++;
for (1..$sub_iter) {
my $class = "Bench::Bas::Sub_${c}";
eval "package $class; use base 'Bench::Base'";
die unless $class->foo;
}
},
use_parent => sub {
$c++;
for (1..$sub_iter) {
my $class = "Bench::Par::Sub_${c}::SubSub${_}";
eval "package $class; use parent -norequire => 'Bench::Base'";
die unless $class->foo;
}
},
use_parent_same_class => sub {
$c++;
for (1..$sub_iter) {
my $class = "Bench::Par::Sub_${c}";
eval "package $class; use parent -norequire => 'Bench::Base'";
die unless $class->foo;
}
},
});
__END__
perl <= 5.8.9
(tested on 5.6.2, 5.8.1, 5.8.9 nearly identical numbers)
Rate use_parent_same_class use_base use_parent
use_base_same_class
use_parent_same_class 121/s -- -28% -42%
-54%
use_base 168/s 39% -- -19%
-36%
use_parent 208/s 72% 24% --
-21%
use_base_same_class 262/s 116% 56% 26%
--
perl > 5.8.9
(tested on 5.10.1, 5.12.1 nearly identical numbers)
Rate use_parent_same_class use_base use_parent
use_base_same_class
use_parent_same_class 9.43/s -- -93% -95%
-96%
use_base 141/s 1392% -- -18%
-48%
use_parent 172/s 1726% 22% --
-36%
use_base_same_class 269/s 2754% 91% 56%
--
perl 5.13.4
Rate use_parent_same_class use_base use_parent
use_base_same_class
use_parent_same_class 76.4/s -- -37% -51%
-66%
use_base 121/s 58% -- -22%
-46%
use_parent 155/s 102% 28% --
-30%
use_base_same_class 222/s 191% 84% 44%
--