????CPU????????дC/C++?????????д????????(Java/C#/pathon…)???????????????????????????????????????????????LMAX??Disruptor???????????????????дJ(rèn)ava?????????????CPU??????????????????????????????????????????????????CPU?????Java??????????漰????CPU?????????????
???????CPU??????????????L1??L2??L3????????????

?????????С????棬????CPU?? ??ζ??????????????????
????L1????CPU?????????С???????????????????L1 Cache(??????????????????L1 Cache?? ????????? L1d Cache?? ???????? L1i Cache)??
????L2 Cache ?????Щ??????256K?????????Щ?????????????????????????????L2 Cache??
????L3 Cache???????????д???????????12MB??????????????????????CPU??????????????L3 Cache??
??????CPU??????????????L1?????????????????????L2??????L3????????????涼???????????????????????????????????·??????????????????????????????????Щ??????????Щ??????L1????????????????????±?????CPU??????????????????????
??????CPU??     ????????????CPU????         ???????????(??λns)
?????????        ????1 cycle
????L1 Cache   ???? ~3-4 cycles                        ~0.5-1 ns
????L2 Cache ????   ~10-20 cycles ????            ~3-7 ns
????L3 Cache ????   ~40-45 cycles ????            ~15 ns
??????????????????????????????????       ~20 ns
??????? ??????????~120-240 cycles                ~60-120ns
????????CPU-Z?????CPU??????????

??????linux???????????????????

?????????????CPU???????????????????????(Cache line)?????棬???????????????????л???????64???(?????”64-byte line size”???)????????????????????????????????????????л????С???л????????????????仰???CPU??????涼???????У??С??λ???????
????????ζ????????кú?????????е????????????????????????????????????
public class L1CacheMiss {
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));
}
}
}