public class TablePerformanceTest { private Lattice table; private void setTable(Lattice table) {
this.table = table;
} private void performanceTest(List<Filter> setF, List<EndPointConnection> con) { LogaritmicSequence sequence = new LogaritmicSequence(1, 2000, 9); int j = 0;
/*
for (Long seq : sequence) { System.out.print(seq);
this.addTable(setF.subList(j, j + seq.intValue()), con);
this.lesserTable(setF.subList(j, j + seq.intValue()), con);
this.upperTable(setF.subList(j, j + seq.intValue()), con);
this.removeTable(setF.subList(j, j + seq.intValue()), con);
System.out.println();
j = j + seq.intValue(); }
* *
*/
this.addTable(setF.subList(0, 1), con);
}
@Test
public void performance1() { int sizeTest = 10000;
EndPointConnection con = new DummyEP();
SienaWorkload filerGene = new SienaWorkload();
Set<EndPointConnection> conns = new HashSet<EndPointConnection>(1);
conns.add(con);
List<Filter> setF = filerGene.createFilters(sizeTest, conns).get(con); //only one conection

System.out.println("performance of Counting table");
this.setTable(new TableCounting());
performanceTest(setF, new ArrayList<EndPointConnection>(conns)); this.setTable(new TableCounting());
performanceTest(setF, new ArrayList<EndPointConnection>(conns)); this.setTable(new TableCounting());
performanceTest(setF, new ArrayList<EndPointConnection>(conns)); this.setTable(new TableCounting());
performanceTest(setF, new ArrayList<EndPointConnection>(conns));
/*
System.out.println("performance of Normal Lattice table");
this.setTable(new TableLattice());
performanceTest(setF, new ArrayList<EndPointConnection>(conns)); for(int i = 0;i <18 ; i++)
{
conns.add(new DummyEP());
}

//only twenty conections
System.out.println("performance of Normal Lattice table con 20 conections");
this.setTable(new TableLattice());
performanceTest(setF, new ArrayList<EndPointConnection>(conns));
*/ }
@Test
public void performance() { int sizeTest = 10000;
EndPointConnection con = new DummyEP();
SienaWorkload filerGene = new SienaWorkload();
Set<EndPointConnection> conns = new HashSet<EndPointConnection>(1);
conns.add(con);
List<Filter> setF = filerGene.createFilters(sizeTest, conns).get(con); //only one conection

System.out.println("performance of Counting table");
this.setTable(new TableCounting());
performanceTest(setF, new ArrayList<EndPointConnection>(conns)); this.setTable(new TableCounting());
performanceTest(setF, new ArrayList<EndPointConnection>(conns)); this.setTable(new TableCounting());
performanceTest(setF, new ArrayList<EndPointConnection>(conns)); this.setTable(new TableCounting());
performanceTest(setF, new ArrayList<EndPointConnection>(conns));
/*
System.out.println("performance of Normal Lattice table");
this.setTable(new TableLattice());
performanceTest(setF, new ArrayList<EndPointConnection>(conns)); for(int i = 0;i <18 ; i++)
{
conns.add(new DummyEP());
}

//only twenty conections
System.out.println("performance of Normal Lattice table con 20 conections");
this.setTable(new TableLattice());
performanceTest(setF, new ArrayList<EndPointConnection>(conns));
*/ }
@Test
public void performance2() { int sizeTest = 10000;
EndPointConnection con = new DummyEP();
SienaWorkload filerGene = new SienaWorkload();
Set<EndPointConnection> conns = new HashSet<EndPointConnection>(1);
conns.add(con);
List<Filter> setF = filerGene.createFilters(sizeTest, conns).get(con); //only one conection

System.out.println("performance of Counting table");
this.setTable(new TableCounting());
performanceTest(setF, new ArrayList<EndPointConnection>(conns)); this.setTable(new TableCounting());
performanceTest(setF, new ArrayList<EndPointConnection>(conns)); this.setTable(new TableCounting());
performanceTest(setF, new ArrayList<EndPointConnection>(conns)); this.setTable(new TableCounting());
performanceTest(setF, new ArrayList<EndPointConnection>(conns));
/*
System.out.println("performance of Normal Lattice table");
this.setTable(new TableLattice());
performanceTest(setF, new ArrayList<EndPointConnection>(conns)); for(int i = 0;i <18 ; i++)
{
conns.add(new DummyEP());
}

//only twenty conections
System.out.println("performance of Normal Lattice table con 20 conections");
this.setTable(new TableLattice());
performanceTest(setF, new ArrayList<EndPointConnection>(conns));
*/ }


public void addTable(List<Filter> setF, List<EndPointConnection> con) {

int filSize = setF.size() / con.size();
int sum = setF.size() % con.size();
int size = 0;

for (int i = 0; i < con.size(); i++) {
size = size + filSize;
if (i < sum) {
size++;
}
for (int j = 0; j < size; j++) {
long start = System.nanoTime();
this.table.add(setF.get(j), con.get(i));
long end = System.nanoTime();
long timeNano= end - start;
long us = TimeUnit.NANOSECONDS.toMicros(timeNano);
System.out.print(" add " + us);

}
} } private Long removeTable(List<Filter> setF, List<EndPointConnection> con) { MyRun run = new MyRun(setF, con) { @Override
protected void doWork(Filter filter,EndPointConnection con) {
table.remove(filter, con);
}
};
Long timeNano = measureTime(run);
long us = TimeUnit.NANOSECONDS.toMicros(timeNano);
System.out.print(" remove " + us);
return timeNano;
} private Long upperTable(List<Filter> setF, List<EndPointConnection> con) { MyRun run = new MyRun(setF, con) { @Override
protected void doWork(Filter filter,EndPointConnection con) {
table.uppers(filter, con);
}
};
Long timeNano = measureTime(run);
long us = TimeUnit.NANOSECONDS.toMicros(timeNano);
System.out.print(" upper " + us);
return timeNano;
} private Long lesserTable(List<Filter> setF, List<EndPointConnection> con) { MyRun run = new MyRun(setF, con) { @Override
protected void doWork(Filter filter,EndPointConnection con) {
table.lessers(filter, con);
}
};
Long timeNano = measureTime(run);
long us = TimeUnit.NANOSECONDS.toMicros(timeNano);
System.out.print(" lesser " + us);
return timeNano;
} private long measureTime(Runnable run) {

long start = System.nanoTime();
run.run();

long end = System.nanoTime(); return end - start;
}

private static class MyRun implements Runnable { private List<Filter> filterList;
private List<EndPointConnection> conn; public MyRun(List<Filter> filterList, List<EndPointConnection> con) { this.filterList = filterList;
this.conn = con;
} @Override
public void run() { int filSize = filterList.size() / conn.size();
int sum = filterList.size() % conn.size();
int size = 0; for (int i = 0; i < conn.size(); i++) {
size = size + filSize;
if (i < sum) {
size++;
}
for (int j = 0; j < size; j++) {
doWork(filterList.get(j), conn.get(i));
}
}
} protected void doWork(Filter filter, EndPointConnection conn) {
}
}} add 2234 add 469 add 1274 add 346performance of Counting table
 add 493 add 428 add 414 add 1402performance of Counting table
 add 693 add 1147 add 632 add 1656Tperformance of Counting table
 add 165 add 360 add 349 add 332performance of Counting table
 add 521 add 453 add 451 add 547performance of Counting table
 add 256 add 405 add 373 add 385
测试performance