in reply to Show that using references is faster
use Benchmark qw(cmpthese); @a = 1..1_000_000; sub flat { my $array = \@_ } sub flatcopy { my @copy = @_ } sub byref { my $array = $_[0] } sub refcopy { my @copy = @$_[0] } cmpthese(-1, { flat => sub { flat(@a) }, flatcopy => sub { flatcopy(@a) }, byref => sub { byref(@a) }, refcopy => sub { refcopy(@a) } }); __END__ Rate flatcopy flat refcopy byref flatcopy 3.24/s -- -77% -91% -91% flat 14.3/s 342% -- -59% -61% refcopy 35.3/s 987% 146% -- -3% byref 36.3/s 1020% 153% 3% --
|
|---|