in reply to Re: aliasing
in thread aliasing

While not negating your statements, I'd like to point out a third option, with Benchmarking. It's a middle of the road option.
#!/usr/local/bin/perl use strict; use Benchmark qw[ cmpthese ]; sub r{ @_[ 0 .. $#_ ] = reverse @_ } sub s{ @{$_[0]} = reverse @{$_[0]} } our @n = 1 .. 1000; cmpthese( -3, { normal_reverse => q[ my @r = reverse @n; ], aliased_reverse => q[ my @r = &r( @n ); ], aliased_ref_reverse => q[ &s( \@n ); ], }); __END__ Rate aliased_reverse aliased_ref_reverse norm +al_reverse aliased_reverse 644/s -- -57% + -77% aliased_ref_reverse 1508/s 134% -- + -46% normal_reverse 2793/s 334% 85% + --

------
We are the carpenters and bricklayers of the Information Age.

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Replies are listed 'Best First'.
Re: Re: Re: aliasing
by BrowserUk (Patriarch) on Jan 12, 2004 at 22:14 UTC

    That certainly stops the memory consumption. For simple reversal, I don't see any benefit, but if the sub is going to do other things as well, I agree that using pass-by-reference rather than value for subs that are designed to modify their arguments makes perfect sense.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Timing (and a little luck) are everything!