in reply to Re: Extraction of List of Coordinates
in thread Extraction of List of Coordinates

In Perl, swaps can be accomplished thus:
if ($num1x > $num2x) { ($num1x, $num2x) = ($num2x, $num1x) }

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^3: Extraction of List of Coordinates
by sgifford (Prior) on Oct 06, 2004 at 05:28 UTC
    I was going to point out the same thing, and that doing it the Perl way is actually faster, but it turns out ikegami's XOR trick is slightly faster:
      After compensating for everything I could think of, XOR still won. Surprisingly, it won against the standard temp-variable swap. Incredibly, it won against a sub that simply returned the numbers in reverse order (in fact, temp swapping generally beat that, too!). I could only think that it wins because the integer math makes things simpler internally.

      I tried different types of arguments, and preprocessing the argument list to force it to integer. Speedup was slight, if there was any at all, for the integer-forced versions. Perl swapping lost pretty consistently in all cases. Temp swapping and return-value swapping beat XOR for swapping strings, sometimes. I got inconsistent results.

      Benchmark code follows...


      Caution: Contents may have been coded under pressure.