SPUG: scalar swap challenge

Brian Hatch spug-list at l.ifokr.org
Wed Oct 8 16:14:47 CDT 2003



> swap challenge> A swap code fragment typically looks like this.
> swap challenge> 
> swap challenge>     $temp = $left;
> swap challenge>     $right = $left;
> swap challenge>     $left = $temp;

I think many of us will know the trick you're thinking of.
However the fact is that a temporary variable will be
faster (three assignments vs three mathematical operations).



--
Brian Hatch                  The Theorem Theorem:
   Systems and
   Security Engineer           If If, Then Then.
http://www.ifokr.org/bri/

Every message PGP signed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/spug-list/attachments/20031008/59a24aaf/attachment.bin


More information about the spug-list mailing list