in reply to Curious Perl Behavior...

The problem is that you are including the time taken to construct the original (anonymous) array.

Try this and see how you get on (the timings shown are AS 5.10.1 under Vista 64-bit):

#!/user/bin/perl use strict; use warnings; use Benchmark qw[ cmpthese ]; sub sum_copy { my @numbers = @_; my $sum = 0; foreach my $num (@numbers){ $sum += $num } $sum; } sub sum_ref { my ($numbers_ref) = @_; my $sum = 0; foreach my $num (@$numbers_ref){ $sum += $num }; $sum; } our $N //= 1e6; my @numbers = 1 .. $N; cmpthese -3, { copy => sub{ my $sum = sum_copy( @numbers ); }, ref => sub{ my $sum = sum_ref( \@numbers ); }, }; __END__ C:\test>junk28 -N=1e4 Rate copy ref copy 3.92/s -- -59% ref 9.67/s 146% -- C:\test>junk28 -N=1e5 Rate copy ref copy 3.95/s -- -59% ref 9.62/s 144% -- C:\test>junk28 -N=1e6 Rate copy ref copy 3.92/s -- -59% ref 9.66/s 146% --

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

Replies are listed 'Best First'.
Re^2: Curious Perl Behavior...
by ack (Deacon) on May 26, 2010 at 15:23 UTC

    This is consistent with what linuxer was saying, too. This helps me a lot and I like your approach, too.

    Thanks so much, again, for helping me to restore my sense of order in the world. My results were puzzling to me and left with a bit of virtigo.

    My quick look' was *too* quick and, as I noted in my response to linuxer, I forgot one of the lessons that our Benchmarking exist for a reason: they make it easy (easier) to do the job right.

    Again, many thanks BrowseUk.

    ack Albuquerque, NM