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]; }