/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package bench;
import edu.umass.pql.ArithmeticTest;
import edu.umass.pql.DefaultValueDouble;
import edu.umass.pql.DefaultValueInt;
import edu.umass.pql.Env;
import edu.umass.pql.Join;
import edu.umass.pql.PQLFactory;
import edu.umass.pql.Reductor;
import edu.umass.pql.TestBase;
import java.lang.reflect.Method;
import org.junit.Test;
/**
*
* @author Hilmar
*/
public class RuntimeCreatorBench extends TestBase {
public static void main (String [] args) {
RuntimeCreatorBench bench = new RuntimeCreatorBench();
bench.setUp();
for (int i=0; i<11; i++) {
long timeBefore = System.currentTimeMillis();
//bench.idf(new Env());
long usedTime = System.currentTimeMillis() - timeBefore;
System.out.println("Test " + i + ": " + usedTime + " milliseconds..");
}
}
@DefaultValueInt(0)
public static int sumInt (int l, int r) {
return l + r;
}
@DefaultValueDouble(0.0D)
public static double sumDouble (double l, double r) {
return l + r;
}
@Test
public Join idf (Env env) {
/* idf:
Reduce[DEFAULT_MAP(?i0; ?i2, METHOD<sumInt(int,int),null>(?i4): _):
!o3]: { CONTAINS(?o1; !o0); Field(?o0; !o2); EQ_Int(?i1; !i4);
ARRAY_LOOKUP_Int(?o2; _, !i2); }
Ausgabe: o3*/
this.env = env;
Method method = null;
for (int i=0; i<RuntimeCreatorBench.class.getMethods().length; i++) {
if (RuntimeCreatorBench.class.getMethods()[i].getName().contains("sumInt"))
method = RuntimeCreatorBench.class.getMethods()[i];
}
PQLFactory.setParallelisationMode(PQLFactory.ParallelisationMode.NONPARALLEL);
Join p = PQLFactory.Reduction( new Reductor [] {PQLFactory.Reductors.N_DEFAULT_MAP(i0r, i2r, PQLFactory.Reductors.METHOD_ADAPTER(method, i4r, _), o3w) },
PQLFactory.CONTAINS(o1r, o0w),
PQLFactory.FIELD(env.v_object[0].getClass(), o0r, o2w),
PQLFactory.EQ_Int(i1r, i4w),
PQLFactory.ARRAY_LOOKUP_Int(o2r, _ ,i2w)
);
return p;
}
@Test
public Join bonus (Env env) {
/*bonus:
Reduce[MAP(?o0, ?d0): !o5]: { CONTAINS(?o1; !o0); Field(?o0; !o2);
Field(?o2; !d1); Reduce[METHOD<sumDouble(double,double),null>(?d2):
!d4]: { Field(?o0; !o4); CONTAINS(?o4; !o3); Field(?o3; !d2); };
MUL_Double(?d1, ?d4; !d0); }
Ausgabe: o5*/
this.env = env;
Method method = null;
for (int i=0; i<RuntimeCreatorBench.class.getMethods().length; i++) {
if (RuntimeCreatorBench.class.getMethods()[i].getName().contains("sumDouble"))
method = RuntimeCreatorBench.class.getMethods()[i];
}
final int d4r = Env.encodeReadVar(TYPE_DOUBLE, 4);
final int d4w = Env.encodeWriteVar(TYPE_DOUBLE, 4);
PQLFactory.setParallelisationMode(PQLFactory.ParallelisationMode.NONPARALLEL);
Join p = PQLFactory.Reduction( new Reductor [] {PQLFactory.Reductors.MAP(o0r, d0r, o5w) },
PQLFactory.CONTAINS(o0r, o2w),
PQLFactory.FIELD(env.v_object[2].getClass(), o2r, d1w),
PQLFactory.Reduction( new Reductor [] {PQLFactory.Reductors.METHOD_ADAPTER(method, d2r, d4w) },
PQLFactory.FIELD(env.v_object[0].getClass(), o0r, o4w),
PQLFactory.CONTAINS(o4r, o3w),
PQLFactory.FIELD(env.v_object[3].getClass(), o3r, d2w)
),
PQLFactory.MUL_Double(d1r, d4r, d0w)
);
return p;
}
@Test
public Join threegrep (Env env) {
/*threegrep:
Reduce[SET(?o1): !o4]: { ARRAY_LOOKUP_Object(?o2; _, !o1);
ARRAY_LOOKUP_Byte(?o1; !i6, ?i0); INT_RANGE_CONTAINS(?i12, ?i13;
?i6); ADD_Int(?i6, ?i1; !i8); ARRAY_LOOKUP_Byte(?o1; ?i8, ?i2);
ADD_Int(?i6, ?i3; !i10); ARRAY_LOOKUP_Byte(?o1; ?i10, ?i4); }
Ausgabe: o4*/
this.env = env;
final int i12r = Env.encodeReadVar(TYPE_INT, 12);
final int i13r = Env.encodeReadVar(TYPE_INT, 13);
final int i8r = Env.encodeReadVar(TYPE_INT, 8);
final int i8w = Env.encodeWriteVar(TYPE_INT, 8);
final int i10r = Env.encodeReadVar(TYPE_INT, 10);
final int i10w = Env.encodeWriteVar(TYPE_INT, 10);
env.v_object[1] = benchmarks.threegrep.Generator.data_array[0];
env.v_object[2] = benchmarks.threegrep.Generator.data_set.toArray();
PQLFactory.setParallelisationMode(PQLFactory.ParallelisationMode.NONPARALLEL);
Join p = PQLFactory.Reduction( new Reductor [] {PQLFactory.Reductors.SET(o1r, o4w)},
PQLFactory.ARRAY_LOOKUP_Object(o2r, _, o1w),
PQLFactory.ARRAY_LOOKUP_Byte(o1r, i6w, i0r),
PQLFactory.INT_RANGE_CONTAINS(i12r, i13r, i6r),
PQLFactory.ADD_Int(i6r, i1r, i8w),
PQLFactory.ARRAY_LOOKUP_Byte(o1r, i8r, i2r),
PQLFactory.ADD_Int(i6r, i3r, i10w),
PQLFactory.ARRAY_LOOKUP_Byte(o1r, i10r, i4r)
);
return p;
}
@Test
public Join webgraph (Env env) {
/*webgraph:
Reduce[SET(?o0): !o8]: { CONTAINS(?o1; !o0); Field(?o0; !o3);
CONTAINS(?o3; !o2); Field(?o2; !o5); Field(?o5; !o6);
CONTAINS(?o6; !o4); Field(?o4; ?o0); }
Ausgabe: o8*/
this.env = env;
final int o6r = Env.encodeReadVar(TYPE_OBJECT, 6);
final int o6w = Env.encodeWriteVar(TYPE_OBJECT, 6);
final int o8w = Env.encodeWriteVar(TYPE_OBJECT, 8);
PQLFactory.setParallelisationMode(PQLFactory.ParallelisationMode.NONPARALLEL);
Join p = PQLFactory.Reduction( new Reductor [] {PQLFactory.Reductors.SET(o0r, o8w)},
PQLFactory.CONTAINS(o1r, o0w),
PQLFactory.FIELD(env.v_object[0].getClass(), o0r, o3w),
PQLFactory.CONTAINS(o3r, o2w),
PQLFactory.FIELD(env.v_object[2].getClass(), o2r, o5w),
PQLFactory.FIELD(env.v_object[5].getClass(), o5r, o6w),
PQLFactory.CONTAINS(o6r, o4w),
PQLFactory.FIELD(env.v_object[4].getClass(), o4r, o0r)
);
return p;
}
public void compute(Join j) {
checkTrue(j);
}
}