#!/usr/bin/perl -w use Benchmark qw( cmpthese ); # for sake of others ;) use strict; package ArgTest; sub shifty_1arg { my $this = shift; my $first_arg = shift; $$this += $first_arg; } sub shifty_3args { my $this = shift; my $first_arg = shift; my $second_arg = shift; my $third_arg = shift; $$this += $first_arg + $second_arg + $third_arg; } sub argumentative_1arg { my( $this, $first_arg ) = @_; $$this += $first_arg; } sub argumentative_3args { my( $this, $first_arg, $second_arg, $third_arg ) = @_; $$this += $first_arg + $second_arg + $third_arg; } sub direct_1arg { ${$_[0]} += $_[1]; } sub direct_3args { ${$_[0]} += $_[1] + $_[2] + $_[3]; } # main /------------------------------------------------ package main; my $total; bless( my $object = \$total, 'ArgTest' ); my @args = ( 1 .. 3 ); cmpthese( 1_000_000, { shifty_1arg => sub { $object->shifty_1arg( @args ) }, argumentative_1arg => sub { $object->argumentative_1arg( @args ) }, direct_1arg => sub { $object->direct_1arg( @args ) }, shifty_3args => sub { $object->shifty_3args( @args ) }, argumentative_3args => sub { $object->argumentative_3args( @args ) }, direct_3args => sub { $object->direct_3args( @args ) }, } ); print "total: $total\n"; __END__ Benchmark: timing 1000000 iterations of argumentative_1arg, argumentative_3args, direct_1arg, direct_3args, shifty_1arg, shifty_3args... argumentative_1arg: 1 wallclock secs ( 1.36 usr + 0.00 sys = 1.36 CPU) @ 735835.17/s (n=1000000) argumentative_3args: 3 wallclock secs ( 1.80 usr + 0.00 sys = 1.80 CPU) @ 556173.53/s (n=1000000) direct_1arg: 0 wallclock secs ( 1.00 usr + 0.00 sys = 1.00 CPU) @ 1000000.00/s (n=1000000) direct_3args: 1 wallclock secs ( 1.19 usr + 0.00 sys = 1.19 CPU) @ 841750.84/s (n=1000000) shifty_1arg: 3 wallclock secs ( 1.59 usr + 0.00 sys = 1.59 CPU) @ 627746.39/s (n=1000000) shifty_3args: 3 wallclock secs ( 2.34 usr + 0.00 sys = 2.34 CPU) @ 426621.16/s (n=1000000) Rate shifty_3args