Search in sources :

Example 1 with BaseTimingTask

use of uk.ac.sussex.gdsc.test.utils.BaseTimingTask in project GDSC-SMLM by aherbert.

the class RampedSelectionStrategyTest method speedTest.

private static void speedTest(final int size, boolean faster, int runs) {
    final long[] sum = RampedSelectionStrategy.createRampedSum(size);
    final TimingService ts = new TimingService(runs);
    ts.execute(new BaseTimingTask("search" + size) {

        @Override
        public Object getData(int index) {
            return sum;
        }

        @Override
        public Object run(Object data) {
            for (int key = (int) sum[sum.length - 1]; key-- > 0; ) {
                RampedSelectionStrategy.search(sum, key);
            }
            return null;
        }

        @Override
        public int getSize() {
            return 1;
        }
    });
    ts.execute(new BaseTimingTask("binarySearch" + size) {

        @Override
        public Object getData(int index) {
            return sum[index];
        }

        @Override
        public Object run(Object data) {
            for (int key = (int) sum[sum.length - 1]; key-- > 0; ) {
                RampedSelectionStrategy.binarySearch(sum, key);
            }
            return null;
        }

        @Override
        public int getSize() {
            return 1;
        }
    });
    final int n = ts.repeat();
    ts.repeat(n);
    if (logger.isLoggable(Level.INFO)) {
        logger.info(ts.getReport());
    }
    final TimingResult slow = ts.get((faster) ? ts.getSize() - 2 : ts.getSize() - 1);
    final TimingResult fast = ts.get((faster) ? ts.getSize() - 1 : ts.getSize() - 2);
    logger.log(TestLogUtils.getTimingRecord(slow, fast));
}
Also used : TimingResult(uk.ac.sussex.gdsc.test.utils.TimingResult) TimingService(uk.ac.sussex.gdsc.test.utils.TimingService) BaseTimingTask(uk.ac.sussex.gdsc.test.utils.BaseTimingTask)

Example 2 with BaseTimingTask

use of uk.ac.sussex.gdsc.test.utils.BaseTimingTask 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

BaseTimingTask (uk.ac.sussex.gdsc.test.utils.BaseTimingTask)2 TimingResult (uk.ac.sussex.gdsc.test.utils.TimingResult)2 TimingService (uk.ac.sussex.gdsc.test.utils.TimingService)2 UniformRandomProvider (org.apache.commons.rng.UniformRandomProvider)1 SeededTest (uk.ac.sussex.gdsc.test.junit5.SeededTest)1