CacheUtil.java
1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package io.mycat.route.util;
/**
* Created by 862911 on 2016/5/4.
*/
public class CacheUtil {
private static final int RUNS = 10;
private static final int DIMENSION_1 = 1024 * 1024;
private static final int DIMENSION_2 = 6;
private static long[][] longs;
public static void main(String[] args) throws Exception {
Thread.sleep(10000);
longs = new long[DIMENSION_1][];
for (int i = 0; i < DIMENSION_1; i++) {
longs[i] = new long[DIMENSION_2];
for (int j = 0; j < DIMENSION_2; j++) {
longs[i][j] = 0L;
}
}
System.out.println("starting....");
long sum = 0L;
for (int r = 0; r < RUNS; r++) {
final long start = System.nanoTime();
// slow
for (int j = 0; j < DIMENSION_2; j++) {
for (int i = 0; i < DIMENSION_1; i++) {
sum += longs[i][j];
}
}
//fast
// for (int i = 0; i < DIMENSION_1; i++) {
// for (int j = 0; j < DIMENSION_2; j++) {
// sum += longs[i][j];
// }
// }
System.out.println((System.nanoTime() - start));
}
}
}