import java.util.ArrayList;


public class RegionSpeedTest {

	private static long timemarker = -1;
	private static float timetaken;
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int frames = 10000;
		int channels = 2;
		int regionSize = 100;
		int regions = frames / regionSize;
		float sum = 0f;
		
		time("start");
		
		//the contenders - array
		float[][] arrayRep = new float[frames][channels];
		for(int i = 0; i < frames; i++) {
			for(int j = 0; j < channels; j++) {
				arrayRep[i][j] = (float)Math.random(); 
			}
		}
		time("make array");
		
		//region list
		ArrayList<float[][]> regionRep = new ArrayList<float[][]>();
		for(int i = 0; i < regions; i++) {
			float[][] newRegion = new float[regionSize][channels];
			for(int j = 0; j < regionSize; j++) {
				for(int k = 0; k < channels; k++) {
					newRegion[j][k] = (float)Math.random();
				}
				regionRep.add(newRegion);
			}
		}
		time("make region list");
		
		//now grab data
		sum = 0f;
		for(int i = 0; i < frames; i++) {
			for(int j = 0; j < channels; j++) {
				sum += arrayRep[i][j]; 
			}
		}
		time("grab from array");
		
		sum = 0f;
		for(float[][] newRegion : regionRep) {
			for(int j = 0; j < regionSize; j++) {
				for(int k = 0; k < channels; k++) {
					sum += newRegion[j][k]; 
				}
			}
		}
		time("grab from region list");
		
	}
	
	public static void time(String s) {
		if(timemarker != -1) {
			timetaken = (float)(System.currentTimeMillis() - timemarker) / 1000f;
			System.out.println(s + " : " + timetaken);
		}
		timemarker = System.currentTimeMillis();
	}

}
