Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

Is this: if(x >= 5) Slower than if(x > 4)

OpenStudy (anonymous):

I should add that I'm writing in C. But in general, will the compiler rewrite it to fastest from?

OpenStudy (anonymous):

In general, I would expect the compiler to rewrite operations like this to perform as quickly as possible (especially with optimization turned on).

OpenStudy (anonymous):

I think assembler will have both operations so it doesn't matter

OpenStudy (anonymous):

On the x86 architecture, those should compile down to a subtraction and a JG (jump greater) and JGE (jump greater equal) instruction respectively. On ARM, it would be the subtraction and BGT or BGE. Either of these should have the same cost, and all even remotely recent architectures will have dedicated instructions for both branch types.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!