in reply to Performance issues with subroutines/methods

As shmem says, subroutine/method calls are pretty expensive. You can shave some off by removing the shift, as diotalevi suggests. Removing the return shaves off some more:
use Benchmark qw(:all); my $a = 10; my $b = 20; cmpthese(-2, { 'Sub' => sub { my $c = add ($a, $b); }, 'Method' => sub { my $c = __PACKAGE__->meth_add ($a, $b); }, 'Sub^2' => sub { my $c = add2 ($a, $b); }, 'Method^2' => sub { my $c = __PACKAGE__->meth2 ($a, $b); }, 'Method^3' => sub { my $c = __PACKAGE__->meth3 ($a, $b); }, }); sub add { return $_[0] + $_[1]; } sub add2 { $_[0] + $_[1] } sub meth_add { shift; return $_[0] + $_[1]; } sub meth2 { shift; $_[0] + $_[1] } sub meth3 { $_[1] + $_[2] }
Rate Method Method^2 Method^3 Sub Sub^2 Method 892013/s -- -5% -12% -23% -30% Method^2 936229/s 5% -- -7% -20% -27% Method^3 1008242/s 13% 8% -- -13% -21% Sub 1165141/s 31% 24% 16% -- -9% Sub^2 1275428/s 43% 36% 27% 9% --