java - Increment variable Speed -


why ++i 1ms faster i++? what's going on in background in memory.

results:

i++ : 3ms

++i : 2ms

here's method used test.

    int term = integer.max_value;      long starttime = system.currenttimemillis();      for(int = 0; < term;)     {         i++;         // ++i;     }      long endtime = system.currenttimemillis();      system.out.println(endtime - starttime); 

you cannot think in terms of level in java jit wrap code @ machine level unintelligently.

if write ++i or i++, converted byte code exact same instruction set.

bytecode both of these :

code:        0: iconst_0              1: istore_1              2: iload_1               3: iload_0               4: if_icmpge     13        7: iinc          1, 1       10: goto          2       13: return 

Comments