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());
}
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());
}
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();
}
use of gdsc.core.test.TimingService in project GDSC-SMLM by aherbert.
the class FRCTest method computeMirroredIsFaster.
@Test
public void computeMirroredIsFaster() {
// Sample lines through an image to create a structure.
final int size = 2048;
double[][] data = new double[size * 2][];
RandomGenerator r = new Well19937c(30051977);
for (int x = 0, y = 0, y2 = size, i = 0; x < size; x++, y++, y2--) {
data[i++] = new double[] { x + r.nextGaussian() * 5, y + r.nextGaussian() * 5 };
data[i++] = new double[] { x + r.nextGaussian() * 5, y2 + r.nextGaussian() * 5 };
}
// Create 2 images
Rectangle bounds = new Rectangle(0, 0, size, size);
IJImagePeakResults i1 = createImage(bounds);
IJImagePeakResults i2 = createImage(bounds);
int[] indices = Utils.newArray(data.length, 0, 1);
MathArrays.shuffle(indices, r);
for (int i : indices) {
IJImagePeakResults image = i1;
i1 = i2;
i2 = image;
image.add((float) data[i][0], (float) data[i][1], 1);
}
i1.end();
i2.end();
ImageProcessor ip1 = i1.getImagePlus().getProcessor();
ImageProcessor ip2 = i2.getImagePlus().getProcessor();
// Test
FRC frc = new FRC();
FloatProcessor[] fft1, fft2;
fft1 = frc.getComplexFFT(ip1);
fft2 = frc.getComplexFFT(ip2);
final float[] dataA1 = (float[]) fft1[0].getPixels();
final float[] dataB1 = (float[]) fft1[1].getPixels();
final float[] dataA2 = (float[]) fft2[0].getPixels();
final float[] dataB2 = (float[]) fft2[1].getPixels();
final float[] numerator = new float[dataA1.length];
final float[] absFFT1 = new float[dataA1.length];
final float[] absFFT2 = new float[dataA1.length];
TimingService ts = new TimingService(10);
ts.execute(new MyTimingTask("compute") {
public Object run(Object data) {
FRC.compute(numerator, absFFT1, absFFT2, dataA1, dataB1, dataA2, dataB2);
return null;
}
});
ts.execute(new MyTimingTask("computeMirrored") {
public Object run(Object data) {
FRC.computeMirrored(size, numerator, absFFT1, absFFT2, dataA1, dataB1, dataA2, dataB2);
return null;
}
});
ts.execute(new MyTimingTask("computeMirroredFast") {
public Object run(Object data) {
FRC.computeMirroredFast(size, numerator, absFFT1, absFFT2, dataA1, dataB1, dataA2, dataB2);
return null;
}
});
ts.repeat(ts.getSize());
ts.report();
}
use of gdsc.core.test.TimingService in project GDSC-SMLM by aherbert.
the class ErfGaussian2DFunctionTest method functionIsFasterThanEquivalentGaussian2DFunction.
// Speed test verses equivalent Gaussian2DFunction
@Test
public void functionIsFasterThanEquivalentGaussian2DFunction() {
int flags = this.flags & ~GaussianFunctionFactory.FIT_ERF;
final Gaussian2DFunction gf = GaussianFunctionFactory.create2D(1, maxx, maxy, flags, zModel);
boolean zDepth = (flags & GaussianFunctionFactory.FIT_Z) != 0;
final TurboList<double[]> params = new TurboList<double[]>();
final TurboList<double[]> params2 = 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);
if (zDepth) {
// Change to a standard free circular function
a = a.clone();
a[Gaussian2DFunction.X_SD] *= zModel.getSx(a[Gaussian2DFunction.SHAPE]);
a[Gaussian2DFunction.Y_SD] *= zModel.getSy(a[Gaussian2DFunction.SHAPE]);
a[Gaussian2DFunction.SHAPE] = 0;
params2.add(a);
}
}
double[][] x = params.toArray(new double[params.size()][]);
double[][] x2 = (zDepth) ? params2.toArray(new double[params2.size()][]) : x;
int runs = 10000 / x.length;
TimingService ts = new TimingService(runs);
ts.execute(new FunctionTimingTask(gf, x2, 1));
ts.execute(new FunctionTimingTask(gf, x2, 0));
ts.execute(new FunctionTimingTask(f1, x, 2));
ts.execute(new FunctionTimingTask(f1, x, 1));
ts.execute(new FunctionTimingTask(f1, x, 0));
int size = ts.getSize();
ts.repeat(size);
ts.report();
// Sometimes this fails, probably due to JVM optimisations, 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());
}
Aggregations