package org.ratson.pentagrid;

import java.util.Arrays;

import org.ratson.pentagrid.fields.ArrayField;
import org.ratson.pentagrid.fields.DoubleMapField;
import org.ratson.pentagrid.fields.ExcessiveField;
import org.ratson.pentagrid.fields.SimpleMapField;

public class Benchmark {

	private static int initialFldSize = 7; 
	
	private static void doBenchmark( String name, Runnable task, int attempts){
		double[] times = new double[ attempts ];
		System.out.println("Running task "+name+" for "+attempts+" times");
		for( int i = 0; i < attempts; ++ i){
			long startTime = System.currentTimeMillis();
			task.run();
			double dt = 0.001*(System.currentTimeMillis() - startTime);
			times[ i ] = dt;
			System.out.println( ""+i+") "+dt );
		}
		Arrays.sort( times );
		System.out.println("Sorted:"+Arrays.toString(times));
	}
	
	private static Runnable makeTest( final Field field, final Rule r, final int tries, final int steps ){
		return new Runnable(){ 
			@Override
			public void run(){
				for( int j = 0; j < tries; ++j){
					field.setCells( Util.randomField( initialFldSize, 0.5) );
					for (int i = 0; i < steps; ++i ){
						field.evaluate( r );
					}
				}
			}
		}; 
	}

	public static void main(String[] args) throws RuleSyntaxException {
		int nBench = 5;
		Rule r = Rule.parseRule("B3S235");
		int tries = 10;
		int steps = 100;
		
		doBenchmark( "Afld", makeTest( new ArrayField(), r, tries, steps), nBench );			
		doBenchmark( "Efld", makeTest( new ExcessiveField(), r, tries, steps), nBench );			
		doBenchmark( "2fld", makeTest( new DoubleMapField(), r, tries, steps), nBench );			
		doBenchmark( "SimpleMap", makeTest( new SimpleMapField(), r, tries, steps), nBench );			
	}
}

@@ -101,110 +101,8 @@
 ld;%0A
-import org.ratson.pentagrid.fields.DoubleMapField;%0Aimport org.ratson.pentagrid.fields.ExcessiveField;%0A
 impo
@@ -1330,180 +1330,8 @@
 %09%09%09%0A
-%09%09doBenchmark( %22Efld%22, makeTest( new ExcessiveField(), r, tries, steps), nBench );%09%09%09%0A%09%09doBenchmark( %222fld%22, makeTest( new DoubleMapField(), r, tries, steps), nBench );%09%09%09%0A
 %09%09do

remove obsolete classes from the benchmark