Title: improving performance in access to multidimensional array elements
Actually, in the case of bigger arrays (over 60 x 60 elements), the fastest way to copy them is using System.arraycopy. You can insert the following code into MatrixCopyTest and see it for yourself.
 
        startTime = System.currentTimeMillis();
        for (int count = 0; count<iterations; count++)
        {
            double[][] rawCopy = new double[numRows][numCols];
            for (int i=0; i < numRows; i++)
                System.arraycopy(original[i], 0, rawCopy[i], 0, numCols);
            rawCopy = null;
        }
        arrayDuration = System.currentTimeMillis() - startTime;
        change = (ebeDuration - arrayDuration)*100.0;
        System.out.println("array " + arrayDuration);
        System.out.println("improvement " + change/ebeDuration + " %");
        System.out.println("ebe takes " + change/arrayDuration + " % longer");
As a pure theoretical conclusion, the element-by-element copy is the slowest. The copy by row is the fastest up to 60 x 60. From sizes bigger than that value, using System.arraycopy is the fastest. As a side effect, System.arraycopy is more effective with long rows (40 x 400) than with long columns (400 x 40), because of the native call overhead, which occurs in the first case 40 times compared with 400 in the second.
 
Florin
-----Ursprüngliche Nachricht-----
Von: Nathan Bower [mailto:[EMAIL PROTECTED]]
Gesendet: Dienstag, 28. Januar 2003 13:25
An: [EMAIL PROTECTED]
Betreff: Re: [JAVA3D] improving performance in access to multidimensional array element s

Hi Alan,
 
Great program! I have a question for you - I use 2D arrays of integers in my program either of 400x400 cells or 800x800 cells, and operate on the values (perhaps 5-10 accesses to each value) individually. I compiled your program and ran it with what I think are sensible values to test the perfomance gain with this array geometry.
 
javac MatrixCopyTest.java
 
java MatrixCopyTest 400 400 5
ebe 261
row 150
improvement 42.52873563218391 %
ebe takes 74.0 % longer
 
java MatrixCopyTest 400 400 500
ebe 19638
row 17976
improvement 8.463183623586923 %
ebe takes 9.2456608811749 % longer
 
Can you help to explain why the method you describe is slower in this test case?
 
Regards,
 
N

Reply via email to