0
我在一篇文章中閱讀了這篇文章。但在這裏給出的答案是不明確的..Java緩存和空循環檢測
1. is it true?
2. Can anyone explain it better?
3. Is there a document that explains java/JVM caching mechanism overall?
**Which one is faster in Java ?**
for(int i = 100000; i > 0; i--) {}
for(int i = 1; i < 100001; i++) {}
Answer: Which ever is run second with be fastest. The server JVM can detect and
eliminate loops which don't do anything. A method with either loop is compiled when
the loop iterates about 10,000 times. (Based on -XX:CompileThreshold=10000) The first
loop will take time to detect it doesn't do anything, however the second will have been
compiled.
這個討論可能會幫助你http://stackoverflow.com/questions/7854808/hotspot-jit-optimizations – kosa
它被稱爲優化而不是緩存(這從JVM到JVM有所不同)。此鏈接可以讓你開始http://docs.oracle.com/cd/E15289_01/doc.40/e15058/underst_jit.htm – kosa
這也將幫助你,http://stackoverflow.com/questions/7271147/java-多少時間做一個空循環使用 – Jimmy