Brad Appleton wrote:
>
> And I think eliminating
> method calls by precomputing them beforehand would be a big
> speedup (and we all know performance is a big issue with the
> current implementation of Pod::Parser)
>
To save you some work, I'm not sure you'd see much difference except for extremely
short methods like accessors. I know people have the perception that method lookups
are *slow*, but I just don't think it's significant (any more) in most cases. Instance
method lookups aren't so slow that you could write faster perl code, and even if you
could, the returns would be small for any significant instance method. Now, if you
have code that uses *tons* of accessor calls, and you can't unroll your loops a bit,
then speeding up method calls would be very effective.
The below Meaningless Benchmark (tm) shows that for &b, a trivial accessor method,
you gain about 8 or 9% calling B::b($x,...) vs $x->b(...). Add a few more statements
to get a method that actually does something and that margin dwindles. Put all
those tweaks in a program that does any serious I/O (like POD translators) and
you probably won't even notice it. Of course, I may have screwed up the benchmark:
I've had it lying around for awhile but tweaked it a bit today, and so may have
introduced a bug.
Instance method lookups have gotten noticably better since 5.00503.
- Barrie
perl-5.006:
Rate B->b($v) $y->b($v) $x->b($v) A::b($x,$v)
B->b($v) 95467/s -- -26% -26% -32%
$y->b($v) 128478/s 35% -- -0% -8%
$x->b($v) 128478/s 35% 0% -- -8%
A::b($x,$v) 139636/s 46% 9% 9% --
Rate $q=B->b() $q=$y->b() $q=$x->b() $q=A::b($x)
$q=B->b() 80389/s -- -29% -29% -34%
$q=$y->b() 113551/s 41% -- -0% -7%
$q=$x->b() 113778/s 42% 0% -- -7%
$q=A::b($x) 122530/s 52% 8% 8% --
Rate B->a($v) $x->a($v) $y->a($v) A::a($x,$v)
B->a($v) 270491/s -- -39% -40% -49%
$x->a($v) 446835/s 65% -- -2% -16%
$y->a($v) 454210/s 68% 2% -- -14%
A::a($x,$v) 529329/s 96% 18% 17% --
Rate $q=B->a() $q=$y->a() $q=$x->a() $q=A::a($x)
$q=B->a() 218452/s -- -40% -41% -45%
$q=$y->a() 365562/s 67% -- -2% -9%
$q=$x->a() 371359/s 70% 2% -- -7%
$q=A::a($x) 400773/s 83% 10% 8% --
###############################################################################
## Method-call vs. Function-call comparison.
print "perl-$]:\n\n" ;
use Benchmark qw( cmpthese timethese ) ;
sub A::a {}
sub A::b {
my $self = shift ;
$self->{FOO} = shift if @_ ;
return $self->{FOO} ;
}
@B::ISA = ( 'A' ) ;
$x = bless {}, 'A' ;
$y = bless {}, 'B' ;
$v = 'Some value' ;
hmmm(qw{ A::b($x,$v) B->b($v) $x->b($v) $y->b($v) });
hmmm(qw{ $q=A::b($x) $q=B->b() $q=$x->b() $q=$y->b() });
hmmm(qw{ A::a($x,$v) B->a($v) $x->a($v) $y->a($v) });
hmmm(qw{ $q=A::a($x) $q=B->a() $q=$x->a() $q=$y->a() });
sub hmmm {
cmpthese( timethese( -1,
{
map {
( $_ => eval "sub{$_}" )
} @_
},
'none'
) ) ;
print "\n" ;
}
open ME, $0 and print "#" x 79, "\n", <ME> ;