Apologies if this is not the correct section to post. I have a question on the performance impact of creating temporary variables in Perl. Is there much difference between say
vssub diag { my $x = shift @_; my $y = shift @_; my $x_sq = $x * $x; my $y_sq = $y * $y; my $prod = $x_sq + $y_sq; my $result = sqrt($prod); return $result; }
sub diag { return sqrt( $_[0] * $_[0] + $_[1] * $_[1]); }
Thanks in advance (I guess I'm asking the reasoning behind it, and whether it should have much of an impact if we were repeating similar a lot of times, not to just measure it)
UPDATE: Thanks to all who replied. Sorry I had a typo. The operations were of course supposed to be the same! I didn't need a solution for a specific problem, it was just a theory question so I just did a simple formula as an example. i.e pythagerous
In reply to Very basic question on performance by morrin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |