in reply to Show that using references is faster

The sort is eating up most of your time here. You want something to show the expense of the stack manipulations in passing the array directly. How about returning a count of the elements?

use strict; use Benchmark; my $len = 4000; my @data; push(@data,rand()) for (0..$len); timethese(90000, { 'by_array' => sub { my $count = count_array( @data ); }, 'by_ref' => sub { my $count = count_array_ref( \@data ); }, }); sub count_array { return scalar @_; } sub count_array_ref { return scalar @{ $_[0] }; }