I have this block in my program:
if (x > 0) {
a = 1;
b = 4;
} else {
a = 2;
b = 3;
}
This can be written with ternary operation like this:
a = (x > 0) ? 1 : 2;
b = (x > 0) ? 4 : 3;
The results are equivalents, but it's part of a really critical part of my application, running thousands of times per second. I want to squeeze some microseconds, because this method will grow a little.
My question: in ARM level, which one is faster? I believe the first one creates a branch instruction. But what about the ternary operation? Does it become a branch on iPhone, too? Or iPhone's ARM has a evil opcode to do the job?
BTW, I also saw an evil technique like this:
a = (x > 0) * 1 + (x <= 0) * 2;
Is this really faster?