Reasons For Avoidance in Practice
Most modern compilers can optimize away the temporary variable in the naive swap, in which case the naive swap uses the same amount of memory and the same number of registers as the XOR swap and is at least as fast, and often faster. The XOR swap is also much less readable and completely opaque to anyone unfamiliar with the technique.
On modern CPU architectures, the XOR technique is considerably slower than using a temporary variable to do swapping. One reason is that modern CPUs strive to execute instructions in parallel via instruction pipelines. In the XOR technique, the inputs to each operation depend on the results of the previous operation, so they must be executed in strictly sequential order. If efficiency is of tremendous concern, it is advised to test the speeds of both the XOR technique and temporary variable swapping on the target architecture.
Read more about this topic: XOR Swap Algorithm
Famous quotes containing the words reasons for, reasons, avoidance and/or practice:
“The more one analyses people, the more all reasons for analysis disappear. Sooner or later one comes to that dreadful universal thing called human nature.”
—Oscar Wilde (18541900)
“The source of Pyrrhonism comes from failing to distinguish between a demonstration, a proof and a probability. A demonstration supposes that the contradictory idea is impossible; a proof of fact is where all the reasons lead to belief, without there being any pretext for doubt; a probability is where the reasons for belief are stronger than those for doubting.”
—Andrew Michael Ramsay (16861743)
“Real good breeding, as the people have it here, is one of the finest things now going in the world. The careful avoidance of all discussion, the swift hopping from topic to topic, does not agree with me; but the graceful style they do it with is beyond that of minuets!”
—Thomas Carlyle (17951881)
“No exile at the South Pole or on the summit of Mont Blanc separates us more effectively from others than the practice of a hidden vice.”
—Marcel Proust (18711922)