smiffy has asked for the wisdom of the Perl Monks concerning the following question:
Considering the following two ways of doing the same thing, which is the most efficient in terms of how much work the Perl interpreter has to do, or does it make no difference?
Pass a hashref to the subroutine.
$hr->{'foo'}='bar'; do_something_mutley($hr); sub do_something_mutley { my $lhr=shift; my $baz=$lhr->{'foo'}; # Various stuff would happen here. return ($baz); }
Get the value of the key from the hashref and pass it to the subroutine.
$hr->{'foo'}='bar'; do_something_mutley($hr->{'foo'}); sub do_something_mutley { my $baz=shift; # Various stuff would happen here. return ($baz); }
Please note that the above are code fragments - strict and warnings would be in use.
I really don't think that I'll lose any (or at least not much) sleep over a few CPU cycles but it would be nice to know if there is a difference in overhead between the two methods.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Calling a subroutine - which is most efficient?
by GrandFather (Saint) on Oct 25, 2008 at 22:45 UTC | |
Re: Calling a subroutine - which is most efficient?
by dragonchild (Archbishop) on Oct 26, 2008 at 00:46 UTC | |
Re: Calling a subroutine - which is most efficient?
by smiffy (Pilgrim) on Oct 26, 2008 at 04:28 UTC | |
by mpeever (Friar) on Oct 26, 2008 at 22:06 UTC | |
Re: Calling a subroutine - which is most efficient?
by Anonymous Monk on Oct 25, 2008 at 22:51 UTC |