why is for loop faster than while loop
This question already has an answer here:
Rerun your test with more than ten iterations, but also run more iterations of those iterations, say 10000 in the inner loop and ten in the outer and average the results. They should be close.
The reason that there is variance is a result of the operating system and multi threading. The OS is managing many tasks other than your program and those may take a slightly higher priority than your program. This causes sight delays in your execution.
Having a much bigger sample size should decrease the variance in the results.
链接地址: http://www.djcxy.com/p/86556.html上一篇: 为什么不JVM编译代码的JVM缓存?
下一篇: 为什么循环比while循环更快