Search in sources :

Example 11 with TimingResult

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());
    }
}
Also used : TimingResult(uk.ac.sussex.gdsc.test.utils.TimingResult) UniformRandomProvider(org.apache.commons.rng.UniformRandomProvider) TimingService(uk.ac.sussex.gdsc.test.utils.TimingService) BaseTimingTask(uk.ac.sussex.gdsc.test.utils.BaseTimingTask) SeededTest(uk.ac.sussex.gdsc.test.junit5.SeededTest)

Aggregations

TimingResult (uk.ac.sussex.gdsc.test.utils.TimingResult)11 TimingService (uk.ac.sussex.gdsc.test.utils.TimingService)9 SpeedTag (uk.ac.sussex.gdsc.test.junit5.SpeedTag)6 UniformRandomProvider (org.apache.commons.rng.UniformRandomProvider)5 SeededTest (uk.ac.sussex.gdsc.test.junit5.SeededTest)5 Test (org.junit.jupiter.api.Test)3 FloatProcessor (ij.process.FloatProcessor)2 ArrayList (java.util.ArrayList)2 LocalList (uk.ac.sussex.gdsc.core.utils.LocalList)2 FakeGradientFunction (uk.ac.sussex.gdsc.smlm.function.FakeGradientFunction)2 FastLog (uk.ac.sussex.gdsc.smlm.function.FastLog)2 Gaussian2DFunctionTest (uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunctionTest)2 BaseTimingTask (uk.ac.sussex.gdsc.test.utils.BaseTimingTask)2 ImageProcessor (ij.process.ImageProcessor)1 Rectangle (java.awt.Rectangle)1 SharedStateContinuousSampler (org.apache.commons.rng.sampling.distribution.SharedStateContinuousSampler)1 Fht (uk.ac.sussex.gdsc.core.ij.process.Fht)1 Gradient1Function (uk.ac.sussex.gdsc.smlm.function.Gradient1Function)1 OffsetGradient1Function (uk.ac.sussex.gdsc.smlm.function.OffsetGradient1Function)1 Gaussian2DFunction (uk.ac.sussex.gdsc.smlm.function.gaussian.Gaussian2DFunction)1