Search in sources :

Example 1 with TimingService

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

the class ErfGaussian2DFunctionTest method functionIsFasterUsingForEach.

// Speed test forEach verses equivalent eval() function calls
@Test
public void functionIsFasterUsingForEach() {
    final ErfGaussian2DFunction f1 = (ErfGaussian2DFunction) this.f1;
    final TurboList<double[]> params = new TurboList<double[]>();
    for (double background : testbackground) // Peak 1
    for (double amplitude1 : testamplitude1) for (double shape1 : testshape1) for (double cx1 : testcx1) for (double cy1 : testcy1) for (double[] w1 : testw1) {
        double[] a = createParameters(background, amplitude1, shape1, cx1, cy1, w1[0], w1[1]);
        params.add(a);
    }
    double[][] x = params.toArray(new double[params.size()][]);
    int runs = 10000 / x.length;
    TimingService ts = new TimingService(runs);
    ts.execute(new FunctionTimingTask(f1, x, 2));
    ts.execute(new FunctionTimingTask(f1, x, 1));
    ts.execute(new FunctionTimingTask(f1, x, 0));
    ts.execute(new ForEachTimingTask(f1, x, 2));
    ts.execute(new ForEachTimingTask(f1, x, 1));
    ts.execute(new ForEachTimingTask(f1, x, 0));
    int size = ts.getSize();
    ts.repeat(size);
    ts.report();
    // in the more used eval(...) functions, so skip for now
    if (!TestSettings.ASSERT_SPEED_TESTS)
        return;
    int n = ts.getSize() - 1;
    Assert.assertTrue("0 order", ts.get(n).getMean() < ts.get(n - 3).getMean());
    n--;
    Assert.assertTrue("1 order", ts.get(n).getMean() < ts.get(n - 3).getMean());
    n--;
    Assert.assertTrue("2 order", ts.get(n).getMean() < ts.get(n - 3).getMean());
}
Also used : TurboList(gdsc.core.utils.TurboList) TimingService(gdsc.core.test.TimingService) Gaussian2DFunctionTest(gdsc.smlm.function.gaussian.Gaussian2DFunctionTest) Test(org.junit.Test)

Example 2 with TimingService

use of gdsc.core.test.TimingService 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 3 with TimingService

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

the class FRCTest method computeSineIsFaster.

@Test
public void computeSineIsFaster() {
    int steps = 100000;
    double delta = 2 * Math.PI / steps;
    final double[] a = new double[steps + 1];
    final double[] cosA = new double[steps + 1];
    for (int i = 0; i <= steps; i++) {
        a[i] = i * delta;
        cosA[i] = Math.cos(a[i]);
    }
    TimingService ts = new TimingService(100);
    ts.execute(new MyTimingTask("sin") {

        public Object run(Object data) {
            double d = 0;
            for (int i = 0; i < a.length; i++) d += Math.sin(a[i]);
            return d;
        }
    });
    ts.execute(new MyTimingTask("FastMath.sin") {

        public Object run(Object data) {
            double d = 0;
            for (int i = 0; i < a.length; i++) d += FastMath.sin(a[i]);
            return d;
        }
    });
    ts.execute(new MyTimingTask("getSine") {

        public Object run(Object data) {
            double d = 0;
            for (int i = 0; i < a.length; i++) d += FRC.getSine(a[i], cosA[i]);
            return d;
        }
    });
    ts.repeat(ts.getSize());
    ts.report();
}
Also used : TimingService(gdsc.core.test.TimingService) Test(org.junit.Test)

Example 4 with TimingService

use of gdsc.core.test.TimingService 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)

Example 5 with TimingService

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

the class CustomPoissonDistributionTest method customDistributionIsFasterWithBigMean.

@Test
public void customDistributionIsFasterWithBigMean() {
    // When the mean is above 40 the PoissonDistribution switches to a different
    // sampling method and this is so slow that the speed increase from using 
    // the instance class is negligible. However test it is still faster. If this fails
    // then Apache commons may have changed their implementation and the custom
    // class should be updated.
    TimingService ts = new TimingService(5);
    ts.execute(new StaticTimingTask(40.5, 60));
    ts.execute(new InstanceTimingTask(40.5, 60));
    int size = ts.getSize();
    ts.repeat(size);
    ts.report(size);
    Assert.assertTrue(ts.get(-1).getMean() < ts.get(-2).getMean());
}
Also used : TimingService(gdsc.core.test.TimingService) Test(org.junit.Test)

Aggregations

TimingService (gdsc.core.test.TimingService)14 Test (org.junit.Test)11 TurboList (gdsc.core.utils.TurboList)4 Well19937c (org.apache.commons.math3.random.Well19937c)4 Gaussian2DFunction (gdsc.smlm.function.gaussian.Gaussian2DFunction)3 TimingResult (gdsc.core.test.TimingResult)2 TimingTask (gdsc.core.test.TimingTask)2 GradientCalculator (gdsc.smlm.fitting.nonlinear.gradient.GradientCalculator)2 ValueProcedure (gdsc.smlm.function.ValueProcedure)2 Gaussian2DFunctionTest (gdsc.smlm.function.gaussian.Gaussian2DFunctionTest)2 RandomDataGenerator (org.apache.commons.math3.random.RandomDataGenerator)2 RandomGenerator (org.apache.commons.math3.random.RandomGenerator)2 DenseMatrix64F (org.ejml.data.DenseMatrix64F)2 IJImagePeakResults (gdsc.smlm.ij.results.IJImagePeakResults)1 FloatProcessor (ij.process.FloatProcessor)1 ImageProcessor (ij.process.ImageProcessor)1 Rectangle (java.awt.Rectangle)1