note
adrianh
<blockquote><em>A single method call is about 30 percent slower than a regular call to the same subroutine</em></blockquote>
<p>These days the performance hit for method calls is around 10-15%. I imagine that the caching of method lookups has got better over time.</p>
<code>
use strict;
use warnings;
use Benchmark qw( cmpthese );
{ package Foo;
sub new { bless {}, shift }
sub self { $_[0] }
}
my $o = Foo->new;
cmpthese(-1, {
subroutine => sub { my $o = Foo::self( $o ) },
method => sub { my $o = $o->self },
});
__END__
# perl 5.8.7 on my box gives...
Rate method subroutine
method 579231/s -- -10%
subroutine 643109/s 11% --
</code>
475463
475524