Skip to content

Instantly share code, notes, and snippets.

@killme2008
Created July 20, 2016 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save killme2008/42b8f1e55e68a6706983274c6e8e4fbf to your computer and use it in GitHub Desktop.
Save killme2008/42b8f1e55e68a6706983274c6e8e4fbf to your computer and use it in GitHub Desktop.
java L1 cache miss test
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