The performance question only makes sense in a context where the functional behavior is identical (because if the functionality is different, the correct behavior is superior to the minimally fast), so I assume that you are referring to a situation where the value of the expression is not used? That is, where the sole purpose of the expression is to increase i ? In this situation, the answer is no: there is no difference in performance, and in fact there is no difference at all. I just compiled this class:
public class Foo { public static void main(final String args[]) { int i = Integer.parseInt(args[0]); i++; } }
and calculated the MD5 checksum of the received Foo.class ; and similarly for c ++i version. They had the same checksum, indicating that the two versions were compiled into the same bytecode and therefore would execute literally the same way.
(Naturally, this could theoretically depend on the compiler. Another compiler may decide to compile i++ differently from ++i even in the context where they are equivalent. But I doubt it, and it really should not be worried, even if it is.)
ruakh source share