Assuming those operations are JITted into x86 opcodes without any optimization, there is no difference. A possible x86 pseudo-assembly snippet for the two cases could be:
cmp i, 1
je destination
and:
cmp i, 0
jg destination
The cmp
operation performs a subtraction between the two operands (register i
and immediate 0
), discards the result and sets some flags: positive, negative, overflow etc.
These flags are then used to trigger a conditional jump (i.e. jump if condition), in one case if the two operands are equal, in the second case if the first is greater than the second.
Again, this without considering any software (JVM-wise) and/or hardware optimization. In fact, x86_64 architectures have a complex pipeline with advanced branch-prediction and out-of-order execution, for which these microbenchmarks are almost meaningless. We are long past counting instructions.