5

どうして

        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 );

印刷します5000 ms

        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 );

版画44 ms

2 番目のソリューション 115 倍高速

4

1 に答える 1

7

テストする方が簡単ですint[][]

int[][] arr = new int[size][2];

この場合size、16 バイトのサイズのメモリを割り当てる必要があります。

そしてこの場合

int[][] arr = new int[2][size];

サイズ * 8 バイトのメモリを 2 つ割り当てるだけで済みます。

そして、割り当ては高価な操作です。

于 2013-02-01T08:23:53.973 に答える