Created
July 20, 2016 07:48
-
-
Save killme2008/42b8f1e55e68a6706983274c6e8e4fbf to your computer and use it in GitHub Desktop.
java L1 cache miss test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class L1CacheMiss { | |
private static final int RUNS = 10; | |
private static final int DIMENSION_1 = 1024 * 1024; | |
private static final int DIMENSION_2 = 62; | |
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...."); | |
final long start = System.nanoTime(); | |
long sum = 0L; | |
for (int r = 0; r < RUNS; r++) { | |
for (int j = 0; j < DIMENSION_2; j++) { | |
for (int i = 0; i < DIMENSION_1; i++) { | |
sum += longs[i][j]; | |
} | |
} | |
// for (int i = 0; i < DIMENSION_1; i++) { | |
// for (int j = 0; j < DIMENSION_2; j++) { | |
// sum += longs[i][j]; | |
// } | |
// } | |
} | |
System.out.println("duration = " + (System.nanoTime() - start)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment