use of uk.ac.sussex.gdsc.test.utils.TimingResult in project GDSC-SMLM by aherbert.
the class FilterTest method directCompareMultiFilterIsFaster.
@SeededTest
void directCompareMultiFilterIsFaster(RandomSeed seed) {
Assumptions.assumeTrue(TestSettings.allow(TestComplexity.MEDIUM));
final UniformRandomProvider UniformRandomProvider = RngUtils.create(seed.getSeed());
final MultiFilter f1 = new MultiFilter(0, 0, 0, 0, 0, 0, 0, 0, 0);
final MultiFilter2 f2 = new MultiFilter2(0, 0, 0, 0, 0, 0, 0, 0, 0);
final double[][][] data = new double[1000][][];
for (int i = data.length; i-- > 0; ) {
data[i] = new double[][] { random(f1.getNumberOfParameters(), UniformRandomProvider), random(f1.getNumberOfParameters(), UniformRandomProvider) };
}
final TimingService ts = new TimingService();
ts.execute(new BaseTimingTask("MultiFilter") {
@Override
public Object getData(int index) {
return new MultiFilter[] { (MultiFilter) f1.create(data[index][0]), (MultiFilter) f1.create(data[index][1]) };
}
@Override
public Object run(Object data) {
final MultiFilter f1 = ((MultiFilter[]) data)[0];
final MultiFilter f2 = ((MultiFilter[]) data)[1];
f1.weakest((Filter) f2);
return null;
}
@Override
public int getSize() {
return data.length;
}
});
ts.execute(new BaseTimingTask("MultiFilter direct") {
@Override
public Object getData(int index) {
return new MultiFilter[] { (MultiFilter) f1.create(data[index][0]), (MultiFilter) f1.create(data[index][1]) };
}
@Override
public Object run(Object data) {
final MultiFilter f1 = ((MultiFilter[]) data)[0];
final MultiFilter f2 = ((MultiFilter[]) data)[1];
f1.weakest(f2);
return null;
}
@Override
public int getSize() {
return data.length;
}
});
ts.execute(new BaseTimingTask("MultiFilter2") {
@Override
public Object getData(int index) {
return new MultiFilter2[] { (MultiFilter2) f2.create(data[index][0]), (MultiFilter2) f2.create(data[index][1]) };
}
@Override
public Object run(Object data) {
final MultiFilter2 f1 = ((MultiFilter2[]) data)[0];
final MultiFilter2 f2 = ((MultiFilter2[]) data)[1];
f1.weakest((Filter) f2);
return null;
}
@Override
public int getSize() {
return data.length;
}
});
ts.execute(new BaseTimingTask("MultiFilter2 direct") {
@Override
public Object getData(int index) {
return new MultiFilter2[] { (MultiFilter2) f2.create(data[index][0]), (MultiFilter2) f2.create(data[index][1]) };
}
@Override
public Object run(Object data) {
final MultiFilter2 f1 = ((MultiFilter2[]) data)[0];
final MultiFilter2 f2 = ((MultiFilter2[]) data)[1];
f1.weakest(f2);
return null;
}
@Override
public int getSize() {
return data.length;
}
});
ts.check();
final int size = ts.repeat();
ts.repeat(size);
if (logger.isLoggable(Level.INFO)) {
logger.info(ts.getReport(size));
}
for (int i = 0; i < size; i += 2) {
final TimingResult slow = ts.get(-(i + 2));
final TimingResult fast = ts.get(-(i + 1));
Assertions.assertTrue(slow.getMin() > fast.getMin());
}
}
Aggregations