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.
In reply to Calling a subroutine - which is most efficient? by smiffy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |