title: Is there ever a point to swap two variables without using a third?
body: <p>I know not to use them, but there are techniques to swap two variables without using a third, such as</p>
  
  <pre><code>x ^= y;
  y ^= x;
  x ^= y;
  </code></pre>
  
  <p>and </p>
  
  <pre><code>x = x + y
  y = x - y
  x = x - y 
  </code></pre>
  
  <p>In class the prof mentioned that these were popular 20 years ago when memory was very limited and are still used in high-performance applications today. Is this true? My understanding as to why it's pointless to use such techniques is that:</p>
  
  <ol>
  <li>It can never be the bottleneck using the third variable.</li>
  <li>The optimizer does this anyway.</li>
  </ol>
  
  <p>So is there ever a good time to not swap with a third variable? Is it ever faster?</p>
  
  <p>Compared to each other, is the method that uses XOR vs the method that uses +/- faster? Most architectures have a unit for addition/subtraction and XOR so wouldn't that mean they are all the same speed? Or just because a CPU has a unit for the operation doesn't mean they're all the same speed?</p>