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:
“One of the reasons for the failure of feminism to dislodge deeply held perceptions of male and female behaviour was its insistence that women were victims, and men powerful patriarchs, which made a travesty of ordinary peoples experience of the mutual interdependence of men and women.”
—Rosalind Coward (b. 1953)
“In short, if there were external bodies, it is impossible we should ever come to know it; and if there were not, we might have the very same reasons to think there were that we have now.”
—George Berkeley (16851753)
“Tax avoidance means that you hire a $250,000-fee lawyer, and he changes the word evasion into the word avoidance.”
—Franklin D. Roosevelt (18821945)
“Whatever my own practice may be, I have no doubt that it is a part of the destiny of the human race, in its gradual improvement, to leave off eating animals, as surely as savage tribes have left off eating each other when they came in contact with the more civilized.”
—Henry David Thoreau (18171862)