Examples.Array
Class ArrayTiming

java.lang.Object
  extended byExamples.Array.ArrayTiming

public class ArrayTiming
extends java.lang.Object

Checks if contiguous triangular arrays are faster than standard 2D Java arrays, ColtMatrices and DenseDouble2DMatrices when used in a situation similar to Libor path simulation. Only access to entries is tested. Note that contiguous arrays make a tradeoff between contiguous memory allocation and more complicated index computations. The main questions are:

Run the program with T=20 to remain in the L2-cache. The current setting of T=60 puts us into main memory.

FINDINGS: nothing beats the standard java array. Colt matrices perform worst once the cache is too small. Accessor methods add significantly to the overhead even more than index calculations. Having the array stored contiguously in memory is not worth the effort.

Each sub-loop moves along a 1D array possibly consisting of references to other 1D arrays. One could have the idea to store a reference to the current 1D array at the beginning of each loop to reduce address calculations and repeated bounds checking. This is possible for standard java arrays at every level since nothing is hidden by accessor methods. If this is done too often it decreases performance. Done in the outermost loop there is a small performance gain. See the improved loop for the javaArray.

Summary: the standard java array is fastest and straightforward unimproved loops work very well. Accessor methods exact a heavy toll. Our loops traverse the arrays in a row by row fashion. This follows the way arrays are allocated in main memory.

See also MemoryTraffic which shows that traversing a java array in main memory row by row is significantly (10 times) faster than traversing it column by column. Column by column access is just as bad as complete random access.


Constructor Summary
ArrayTiming()
           
 
Method Summary
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ArrayTiming

public ArrayTiming()
Method Detail

main

public static void main(java.lang.String[] args)