Search in sources :

Example 1 with TimingResult

use of gdsc.core.test.TimingResult in project GDSC-SMLM by aherbert.

the class RampedSelectionStrategyTest method speedTest.

private void speedTest(final int size, boolean faster, int runs) {
    final long[] sum = RampedSelectionStrategy.createSum(size);
    TimingService ts = new TimingService(runs);
    ts.execute(new TimingTask() {

        public Object getData(int i) {
            return sum;
        }

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

        public void check(int i, Object result) {
        }

        public int getSize() {
            return 1;
        }

        public String getName() {
            return "search" + size;
        }
    });
    ts.execute(new TimingTask() {

        public Object getData(int i) {
            return sum[i];
        }

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

        public void check(int i, Object result) {
        }

        public int getSize() {
            return 1;
        }

        public String getName() {
            return "binarySearch" + size;
        }
    });
    int n = ts.repeat();
    ts.repeat(n);
    ts.report();
    TimingResult slow = ts.get((faster) ? ts.getSize() - 2 : ts.getSize() - 1);
    TimingResult fast = ts.get((faster) ? ts.getSize() - 1 : ts.getSize() - 2);
    Assert.assertTrue(slow.getMin() > fast.getMin());
}
Also used : TimingResult(gdsc.core.test.TimingResult) TimingService(gdsc.core.test.TimingService) TimingTask(gdsc.core.test.TimingTask)

Example 2 with TimingResult

use of gdsc.core.test.TimingResult in project GDSC-SMLM by aherbert.

the class FilterTest method directCompareMultiFilterIsFaster.

@Test
public void directCompareMultiFilterIsFaster() {
    RandomGenerator randomGenerator = new Well19937c(System.currentTimeMillis() + System.identityHashCode(this));
    final MultiFilter f1 = new MultiFilter(0, 0, 0, 0, 0, 0, 0);
    final MultiFilter2 f2 = new MultiFilter2(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(), randomGenerator), random(f1.getNumberOfParameters(), randomGenerator) };
    }
    TimingService ts = new TimingService();
    ts.execute(new TimingTask() {

        public Object getData(int i) {
            return new MultiFilter[] { (MultiFilter) f1.create(data[i][0]), (MultiFilter) f1.create(data[i][1]) };
        }

        public Object run(Object data) {
            MultiFilter f1 = ((MultiFilter[]) data)[0];
            MultiFilter f2 = ((MultiFilter[]) data)[1];
            f1.weakest((Filter) f2);
            return null;
        }

        public void check(int i, Object result) {
        }

        public int getSize() {
            return data.length;
        }

        public String getName() {
            return "MultiFilter";
        }
    });
    ts.execute(new TimingTask() {

        public Object getData(int i) {
            return new MultiFilter[] { (MultiFilter) f1.create(data[i][0]), (MultiFilter) f1.create(data[i][1]) };
        }

        public Object run(Object data) {
            MultiFilter f1 = ((MultiFilter[]) data)[0];
            MultiFilter f2 = ((MultiFilter[]) data)[1];
            f1.weakest(f2);
            return null;
        }

        public void check(int i, Object result) {
        }

        public int getSize() {
            return data.length;
        }

        public String getName() {
            return "MultiFilter direct";
        }
    });
    ts.execute(new TimingTask() {

        public Object getData(int i) {
            return new MultiFilter2[] { (MultiFilter2) f2.create(data[i][0]), (MultiFilter2) f2.create(data[i][1]) };
        }

        public Object run(Object data) {
            MultiFilter2 f1 = ((MultiFilter2[]) data)[0];
            MultiFilter2 f2 = ((MultiFilter2[]) data)[1];
            f1.weakest((Filter) f2);
            return null;
        }

        public void check(int i, Object result) {
        }

        public int getSize() {
            return data.length;
        }

        public String getName() {
            return "MultiFilter2";
        }
    });
    ts.execute(new TimingTask() {

        public Object getData(int i) {
            return new MultiFilter2[] { (MultiFilter2) f2.create(data[i][0]), (MultiFilter2) f2.create(data[i][1]) };
        }

        public Object run(Object data) {
            MultiFilter2 f1 = ((MultiFilter2[]) data)[0];
            MultiFilter2 f2 = ((MultiFilter2[]) data)[1];
            f1.weakest(f2);
            return null;
        }

        public void check(int i, Object result) {
        }

        public int getSize() {
            return data.length;
        }

        public String getName() {
            return "MultiFilter2 direct";
        }
    });
    ts.check();
    int size = ts.repeat();
    ts.repeat(size);
    ts.report();
    for (int i = 0; i < ts.getSize(); i += 2) {
        TimingResult slow = ts.get(i);
        TimingResult fast = ts.get(i + 1);
        Assert.assertTrue(slow.getMin() > fast.getMin());
    }
}
Also used : TimingResult(gdsc.core.test.TimingResult) Well19937c(org.apache.commons.math3.random.Well19937c) TimingService(gdsc.core.test.TimingService) RandomGenerator(org.apache.commons.math3.random.RandomGenerator) TimingTask(gdsc.core.test.TimingTask) Test(org.junit.Test)

Aggregations

TimingResult (gdsc.core.test.TimingResult)2 TimingService (gdsc.core.test.TimingService)2 TimingTask (gdsc.core.test.TimingTask)2 RandomGenerator (org.apache.commons.math3.random.RandomGenerator)1 Well19937c (org.apache.commons.math3.random.Well19937c)1 Test (org.junit.Test)1