in reply to Re^4: Very basic question on performance
in thread Very basic question on performance

Yes, I'll agree. With that in mind, and given another followup from the OP, it seems that what he really wants is this:

sub diag { sqrt( $_[0]^^2 + $_[1]^^2 ); }

...or possibly...

sub diag { sqrt( shift^^2 + shift^^2 ); # Not sure if this is more readable, or + not. }

Or if he's in a really tight loop where every cycle counts, possibly an Inline::C version of the same.


Dave

Replies are listed 'Best First'.
Re^6: Very basic question on performance
by Laurent_R (Canon) on Mar 14, 2014 at 20:01 UTC
    Yes, I agree and had noted the OP's new message. In fact, I would consider this:
    sub diag { my ($x, $y) = @_; sqrt( $x^^2 + $y^^2 ); }
    to still be very fine (perhaps slightly slower, but very clear), but the way the original script was coded with numerous intermediate variables (to store the squares, etc.) actually made the things more complicated to follow than a single and simple math expression which all of us presumably can understand at first glance.