@Before publicvoidinit(){ longs = newlong[DIMENSION_1][]; for (int i = 0; i < DIMENSION_1; i++) { longs[i] = newlong[DIMENSION_2]; for (int j = 0; j < DIMENSION_2; j++) { longs[i][j] = 0L; } } }
@Test publicvoidslow(){ long sum = 0L; for (int r = 0; r < RUNS; r++) { finallong start = System.nanoTime(); for (int j = 0; j < DIMENSION_2; j++) { for (int i = 0; i < DIMENSION_1; i++) { sum += longs[i][j]; } } System.out.println((System.nanoTime() - start)); } }
@Test publicvoidfast(){ long sum = 0L; for (int r = 0; r < RUNS; r++) { finallong start = System.nanoTime(); 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)); } } }