Speed difference between If-Else and Ternary operator in C…?

There’s a good chance that the ternary operator gets compiled into a cmov while the if/else results in a cmp+jmp. Just take a look at the assembly (using -S) to be sure. With optimizations enabled, it won’t matter any more anyway, as any good compiler should produce the same code in both cases.

Leave a Comment