我正在尝试避免即时编译器进行微基准测试,但是我似乎找不到解决方法。时代似乎简直令人难以置信,我相信这就是问题所在。
public static void main(String[] args) throws FileNotFoundException {
insertsort();
}
public static void insertsort (){
int[] a = {7111, 131, 1135, 629, 9951, 4351, 6879, 5204, 8945, 2579, 6297, 6822, 8065, 3103, 7474, 4040, 2095, 7549, 9008, 2897, 7704, 1286, 402, 7014, 5023, 9937, 750, 5590, 1144, 9313, 900, 2183, 9375, 492, 2453, 6819, 1360, 7851, 112, 8825, 2455, 5828, 7547, 5536, 8377, 5742, 9927, 3166, 7275, 983, 9249, 5369, 41, 8723, 723, 9211, 8711, 7045, 5278, 7292, 5487, 45, 1966, 3500, 1894, 3540, 9074, 17, 589, 2420, 1083, 9291, 5257, 5009, 6270, 6336, 6168, 4300, 3976, 9386, 4791, 9251, 1118, 1610, 3952, 7899, 6527, 7876, 5606, 2779, 3248, 8236, 4962, 4846, 8992, 8551, 5125, 6231, 9018, 8355};
int j;
int temp;
int count = 10;
long start = 0;
for (int k = 0; k<count ; k++) {
start = System.nanoTime();
int i = 1;
while (i < a.length) {
j = i;
while (j > 0 && a[j - 1] > a[j]) {
temp = a[j];
a[j] = a[j - 1];
a[j - 1] = temp;
j--;
}
i++;
}
double ftime = (double) (System.nanoTime() - start);
double time = ftime;
System.out.printf("%6.1f ns%n", time);
}
}
这是结果:
83700.0 ns
2100.0 ns
2100.0 ns
2200.0 ns
2200.0 ns
2200.0 ns
2200.0 ns
3200.0 ns
2200.0 ns
2200.0 ns
我应该如何解决这个问题?