#!/usr/bin/perl -w use Benchmark; 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]; } sub value { return ${$_[0]} } package main; my $total; bless( my $object = \$total, 'ArgTest' ); my @args = ( 1 .. 3 ); timethese( 2_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: " . $object->value . "\n";