I am currently trying to get my code execution to be as fast as possible. And I saw this online :
They advice to replace :
if (a == b && c == d && e == f )
by
if ( ((a-b)|(c-d)|(e-f)) == 0 )
However the conditions are no longer respected when translated that way? I mean the first code asks for every condition to be satisfied while the second one asks for only one out of the three to be true, am I wrong? If I am not is :
The "&&" operator stops evaluation if the first FALSE condition is found. That's faster as long as not all conditions are TRUE.
No. The condition is ... == 0 which is determined after the entire calculation. The calculation is done for all three differences because the bitwise "|" operator simply calculates, while logical "||" would treat each single non-zero difference as TRUE and then stops evaluation immediately.
That's wrong because a positive difference can be compensated by a negative difference.