I was looking for alternate options to swap two numbers and came across the link How to swap two numbers
In the comments section its been mentioned that using temporary variable is better. Below is the comment I copied form the link
If we look at the problem at the CPU instructions perspective, use tmp will be better than all above 3 method, i have run a benchmark agains all those 4 method (including the 4th by ?using temp variable). without surprise, the 4th way beats all above 3 method. And the reason is how CPU move the variable into register and how many register we need to use.
But I am not able to find a clue on how it works. Can someone explain me how it works at the processor level and why temp variable is better (if it is)?