Why
long t = System.currentTimeMillis();
int size = 3333333;
int[][][] arr = new int[size][6][2];
// int[][][] arr= new int[2][6][size];
pr(System.currentTimeMillis() - t );
prints 5000 ms
but
long t = System.currentTimeMillis();
int size = 3333333;
// int[][][] arr = new int[size][6][2];
int[][][] arr= new int[2][6][size];
pr(System.currentTimeMillis() - t );
prints 44 ms
Second solution 115 time faster
It’s simplier to test
int[][]In this case you have to allocate
sizepieces of memory with size of 16 bytes.And in this case
you have only to allocate 2 pieces of memory of size*8 bytes.
And allocating is expensive operation.