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:
“Its an old trick now, God knows, but it works every time. At the very moment women start to expand their place in the world, scientific studies deliver compelling reasons for them to stay home.”
—Mary Kay Blakely (20th century)
“... to a poet, the human community is like the community of birds to a bird, singing to each other. Love is one of the reasons we are singing to one another, love of language itself, love of sound, love of singing itself, and love of the other birds.”
—Sharon Olds (b. 1942)
“The American Dream, the idea of the happy ending, is an avoidance of responsibility and commitment.”
—Jill Robinson (b. 1936)
“Indubitably, Magick is one of the subtlest and most difficult of the sciences and arts. There is more opportunity for errors of comprehension, judgement and practice than in any other branch of physics.”
—Aleister Crowley (18751947)