performance - Is there ever a point to swap two variables without using a third? -



performance - Is there ever a point to swap two variables without using a third? -

i know not utilize them, there techniques swap 2 variables without using third, such as

x ^= y; y ^= x; x ^= y;

and

x = x + y y = x - y x = x - y

in class prof mentioned these popular 20 years ago when memory limited , still used in high-performance applications today. true? understanding why it's pointless utilize such techniques that:

it can never bottleneck using 3rd variable. the optimizer anyway.

so there ever time not swap 3rd variable? ever faster?

compared each other, method uses xor vs method uses +/- faster? architectures have unit addition/subtraction , xor wouldn't mean same speed? or because cpu has unit operation doesn't mean they're same speed?

these techniques still of import know programmers write firmware of average washing machine or so. lots of kind of hardware still runs on z80 cpus or similar, no more 4k of memory or so. outside of scene, knowing these kinds of algorithmic "trickery" has, say, no real practical use.

(i want remark though nonetheless, programmers remember , know kind of stuff turn out improve programmers "regular" applications "peers" won't bother. exactly because latter take mental attitude of "memory big plenty anyway" far.)

performance algorithm assembly language-agnostic swap

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -