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
|
Title: improving performance in access to multidimensional array elements
- [JAVA3D] AW: [JAVA3D] improving performance in access to ... Florin Herinean
- Florin Herinean