use strict; use warnings; use Benchmark qw(:all); my @a = ( 'a','b','c','d','e','g','h', 'a','b','c','d','e','g','h', 'a','b','c','d','e','g','h', 'a','b','c','d','e','g','h', 'a','b','c','d','e','g','h', 'a','b','c','d','e','g','h', 'a','b','c','d','e','g','h', 'a','b','c','d','e','g','h', 'a','b','c','d','e','g','h', 'a','b','c','d','e','g','h', ); my $a_ref = [ 'a','b','c','d','e','g','h', 'a','b','c','d','e','g','h', 'a','b','c','d','e','g','h', 'a','b','c','d','e','g','h', 'a','b','c','d','e','g','h', 'a','b','c','d','e','g','h', 'a','b','c','d','e','g','h', 'a','b','c','d','e','g','h', 'a','b','c','d','e','g','h', 'a','b','c','d','e','g','h', ]; cmpthese(-2, { 'a copy' => sub { my @b = a_copy(@a); }, 'a ref 1' => sub { my $b = a_ref_1(\@a); }, 'a ref 2' => sub { my $b = a_ref_2(\@a); }, 'a ref 3' => sub { my $b = a_ref_1($a_ref); }, 'a ref 4' => sub { my $b = a_ref_2($a_ref); }, }); sub a_copy { my (@a) = @_; return @a; } sub a_ref_1 { my ($a) = @_; return $a; } sub a_ref_2 { return $_[0]; } #### Rate a copy a ref 1 a ref 3 a ref 2 a ref 4 a copy 171189/s -- -97% -97% -97% -98% a ref 1 5073751/s 2864% -- -15% -21% -35% a ref 3 5946679/s 3374% 17% -- -7% -23% a ref 2 6408282/s 3643% 26% 8% -- -17% a ref 4 7753141/s 4429% 53% 30% 21% --