为什么 JIT 编译器不适用于以下代码?
而且每个单独的循环似乎都需要很长时间
(参见我关于执行时间的另一篇文章。简单循环的速度
public static void main (String[] args) {
for (int j = 0; j < 10; j++) {
float f;
long start = System.nanoTime();
for (int i = 0; i < 2000000000; i++) {
f = i * 0.0001F;
}
long end = System.nanoTime();
long timeToCallNanoTime = System.nanoTime() - end;
long time = Math.max(0, end - start - timeToCallNanoTime);
System.out.println("time: " + time + " ns.");
}
}
结果:
time: 6639317628 ns.
time: 6630196045 ns.
time: 6632583856 ns.
time: 6617596798 ns.
time: 6605243858 ns.
time: 6609097755 ns.
time: 6627151876 ns.
time: 6623427381 ns.
time: 6632506712 ns.
time: 6615870257 ns.