import java.util.ArrayList;
import java.util.Hashtable;


public class ArraysSpeedTest {

	public static void main(String[] args) {
		//compare an array of arrays with an array list of arrays
		int X = 1000000, Y = 2;
		long timenow = 0;
		float timetaken = 0;
		//make the array of arrays
		timenow = System.currentTimeMillis();
		float[][] arrayOfArrays = new float[X][Y];
		for(int i = 0; i < X; i++) {
			for(int j = 0; j < Y; j++) {
				arrayOfArrays[i][j] = 2;
			}
		}
		timetaken = (float)(System.currentTimeMillis() - timenow) / 1000f;
		System.out.println("making array: " + timetaken);
		//make the array list of arrays
		timenow = System.currentTimeMillis();
		ArrayList<float[]> arrayListOfArrays = new ArrayList<float[]>();
		for(int i = 0; i < X; i++) {
			arrayListOfArrays.add(arrayOfArrays[i]);
		}
		timetaken = (float)(System.currentTimeMillis() - timenow) / 1000f;
		System.out.println("making array list: " + timetaken);
		//make the hashtable of arrays
		timenow = System.currentTimeMillis();
		Hashtable<Integer, float[]> hashtableOfArrays = new Hashtable<Integer, float[]>();
		for(int i = 0; i < X; i++) {
			hashtableOfArrays.put(i, arrayOfArrays[i]);
		}
		timetaken = (float)(System.currentTimeMillis() - timenow) / 1000f;
		System.out.println("making hashtable: " + timetaken);
		//now grab them
		//the array of arrays
		timenow = System.currentTimeMillis();
		float x = 0;
		for(int i = 0; i < X; i++) {
			for(int j = 0; j < Y; j++) {
				x += arrayOfArrays[i][j];
			}
		}
		timetaken = (float)(System.currentTimeMillis() - timenow) / 1000f;
		System.out.println("reading array: " + timetaken);
		//the array list of arrays
		timenow = System.currentTimeMillis();
		x = 0;
		for(int i = 0; i < X; i++) {
			float[] f = arrayListOfArrays.get(i);
			for(int j = 0; j < Y; j++) {
				x += f[j];
			}
		}
		timetaken = (float)(System.currentTimeMillis() - timenow) / 1000f;
		timenow = System.currentTimeMillis();
		System.out.println("reading array list: " + timetaken);
		//the hashtable of arrays
		timenow = System.currentTimeMillis();
		x = 0;
		for(int i = 0; i < X; i++) {
			float[] f = hashtableOfArrays.get(i);
			for(int j = 0; j < Y; j++) {
				x += f[j];
			}
		}
		timetaken = (float)(System.currentTimeMillis() - timenow) / 1000f;
		timenow = System.currentTimeMillis();
		System.out.println("reading hashtable: " + timetaken);
	}
}
