java - Resetting a variable later in the code makes an earlier block of code run slower. Why? -
I have the following program. When I saw something unusual, I was roaming with other belongings. Line "y = 3"; It seems that the last block of code can be run as fast as possible. When the line is commented, the first half of the code runs ten times slower than the second half, however, when the line is inappropriate, then both half run at the same speed. Interestingly, the line in question is anything Do not, because at that point y is already 3.
Edit: I added the "y.ystem.out.println (y)" line up "y = 3" and prints it 3. That's why I think it's 3. And I'm measuring the output of the program. Two rows that print, there are two runtime, and the timer code below shows how I measure time.
/ ** * @author lpreams * / public category miscellaneous {public static zero major (string [] args) {new variety (). Run (); } Run Public Zero () {Timer T = New Timer (); T.start (); Int y = integer MIN_VALUE; For {int j = 0; j and lt; integer.mx_evann; ++ j) {for (int i = 0; i I am running this code in Eclipse on OS X 10.9.2. I'm running the latest version of Java My machine is MacBook Pro with a 2.4GHz Core 2 Duo with 8 GB RAM.
Any result you suspect is derived from this micro benchmark. You are not taking an account of JVM warm-up effects.
After saying this, if we can assume that the effect is real i can optimize that loop body before jit optimizer ... when y = 3 assignment is you running in a case where adding a little more "complexity" is interrupting the optimization. It happens. (The value being specified is random, which is to be done by JIT compiler with code generation ... which before y value It will be 3 which you can guess, which can calculate anything. This can affect the JIT compiler behavior.)
Comments
Post a Comment