just for fun, how would you optimize this piece of simple code?
a) i guess most programmer will come up with this: if(x==a)
x=b;
else
x=a;
b) how about this one: x = x==a ? b : a;
c) and this? x = a + b - x;
x = a ^ b ^ x;
Depends on the instruction set of CPU,
a) requirement 2-3 instructions.
b) if a and b are constants, it requires 1 instruction, otherwise 2 instructions.
c) same as b.
However, no doubt that a) is most readable.
Any other idea?
© jiabinary. Powered by WordPress using the DePo Skinny Theme.