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:
“Could truth perhaps be a woman who has reasons for not permitting her reasons to be seen? Could her name perhaps beto speak GreekBaubo?... Oh, those Greeks! They understood how to live: to do that it is necessary to stop bravely at the surface, the fold, the skin, to adore the appearance, to believe in forms, in tones, in words, in the whole Olympus of appearance! Those Greeks were superficialout of profundity!”
—Friedrich Nietzsche (18441900)
“As if her velvet helmet high
Did turret rationality.
She fans her wing up to the winde
As if her Pettycoate were linde
With reasons fleece, and hoises saile
And humming flies in thankfull gaile”
—Edward Taylor (16451729)
“The American Dream, the idea of the happy ending, is an avoidance of responsibility and commitment.”
—Jill Robinson (b. 1936)
“It has always been my practice to cast a long paragraph in a single mould, to try it by my ear, to deposit it in my memory, but to suspend the action of the pen till I had given the last polish to my work.”
—Edward Gibbon (17371794)