That depends entirely on the ISA you're compiling for, and the quality of your compiler's optimizer. Don't optimize prematurely: profile first to find your bottlenecks.
That said, in x86, you'll find that both are equally fast in most cases. In both cases, you'll have a comparison (cmp
) and a conditional jump (jCC
) instructions. However, for (x < 0)
, there may be some instances where the compiler can elide the cmp
instruction, speeding up your code by one whole cycle.
Specifically, if the value x
is stored in a register and was recently the result of an arithmetic operation (such as add
, or sub
, but there are many more possibilities) that sets the sign flag SF in the EFLAGS register, then there's no need for the cmp
instruction, and the compiler can emit just a js
instruction. There's no simple jCC
instruction that jumps when the input was -1.