Very strange result!
。。!
Test methods such as the following
public class Main {public static void main (string[] args) { Long ti = System.currenttimemillis (); for (int i=integer.min_value;i<integer.max_value;i++) { if (i==i) continue; } System.out.println (System.currenttimemillis ()-ti); TI = System.currenttimemillis (); for (int i=integer.min_value;i<integer.max_value;i++) { continue; } System.out.println (System.currenttimemillis ()-ti);}}
Output results
61320
Question 1:
After adding inferences to the For loop, the loop runs at a much worse time.
The above is the problem, look at the following test, you will find more interesting
public class Main {public static void main (string[] args) { Long ti = System.currenttimemillis (); Long c = 0; for (int i=integer.min_value;i<integer.max_value;i++) { C + +; if (i==i) continue; } System.out.println (System.currenttimemillis ()-ti + " " +c); TI = System.currenttimemillis (); c=0; for (int i=integer.min_value;i<integer.max_value;i++) { C + +; Continue; } System.out.println (System.currenttimemillis ()-ti+ " " +c);}}
Same output
42949672957847 4294967295 But in the loop did a + + operation, time-consuming incredibly added nearly 10 times times! I have to say, java!. The efficiency of your execution is dire.。。
。
Java version number: Javac 1.7.0_25
Explanation:
In the for loop to increase the inference and without inference, run time difference why the difference is 200 times times?!
-------------------------------------------------------------------------------------------------
Try again today, the Java version number does not know when it became this: Javac 1.7.0_55 results are no longer the same as the last Test, it seems that the last time a bug was encountered.
。
Don't know Java when you upgrade yourself.
Copyright notice: This article Bo Master original article. Blogs, without consent, may not be reproduced.
Java for loop efficiency test