use of uk.ac.sussex.gdsc.test.junit5.SpeedTag in project GDSC-SMLM by aherbert.
the class FastMathTest method cbrtIsFaster.
// @formatter:on
@SpeedTag
@Test
void cbrtIsFaster() {
Assumptions.assumeTrue(TestSettings.allow(TestComplexity.MEDIUM));
// Q. What is a suitable range for this test?
final int range = 5;
final int steps = 10000;
final double[] x = new double[steps];
final double total = 2 * range;
final double step = total / steps;
for (int i = 0; i < steps; i++) {
x[i] = -range + i * step;
}
final TimingService ts = new TimingService(5);
ts.execute(new MathPow1_3(x));
ts.execute(new FastMathPow1_3(x));
ts.execute(new MathCbrt(x));
ts.execute(new FastMathCbrt(x));
final int size = ts.getSize();
ts.repeat(size);
if (logger.isLoggable(Level.INFO)) {
logger.info(ts.getReport());
}
final TimingResult fast = ts.get(-1);
for (int k = 2; k <= 3; k++) {
final TimingResult slow = ts.get(-k);
logger.log(TestLogUtils.getTimingRecord(slow, fast));
}
}
use of uk.ac.sussex.gdsc.test.junit5.SpeedTag in project GDSC-SMLM by aherbert.
the class FastLogTest method canTestFloatVsDoubleSpeed.
@SpeedTag
@SeededTest
void canTestFloatVsDoubleSpeed(RandomSeed seed) {
// No assertions, this is just a report
Assumptions.assumeTrue(logger.isLoggable(Level.INFO));
Assumptions.assumeTrue(TestSettings.allow(TestComplexity.MEDIUM));
final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
final double[] x = new double[1000000];
final float[] xf = new float[x.length];
for (int i = 0; i < x.length; i++) {
x[i] = nextUniformFloat(rng);
xf[i] = (float) x[i];
}
final TimingService ts = new TimingService(5);
ts.execute(new DoubleTimingTask(new TestLog(new MathLog()), 0, x));
ts.execute(new DoubleTimingTask(new TestLog(new FastMathLog()), 0, x));
for (final int q : new int[] { 11 }) {
final int n = 23 - q;
final IcsiFastLog ff = IcsiFastLog.create(n, DataType.FLOAT);
final IcsiFastLog fd = IcsiFastLog.create(n, DataType.DOUBLE);
final IcsiFastLog ff2 = IcsiFastLog.create(n, DataType.FLOAT);
ts.execute(new DoubleToFloatTimingTask(new TestLog(ff), q, x, xf));
ts.execute(new DoubleToFloatTimingTask(new TestFastLog(ff), q, x, xf));
ts.execute(new FloatTimingTask(new TestLog(ff2), q, xf));
ts.execute(new FloatTimingTask(new TestFastLog(ff2), q, xf));
ts.execute(new DoubleTimingTask(new TestLog(fd), q, x));
ts.execute(new DoubleTimingTask(new TestFastLog(fd), q, x));
// ts.execute(new DoubleToFloatTimingTask(new TestLog(ff), q, x, xf));
// ts.execute(new DoubleToFloatTimingTask(new TestFastLog(ff), q, x, xf));
// ts.execute(new FloatTimingTask(new TestLog(ff2), q, xf));
// ts.execute(new FloatTimingTask(new TestFastLog(ff2), q, xf));
// ts.execute(new DoubleTimingTask(new TestLog(fd), q, x));
// ts.execute(new DoubleTimingTask(new TestFastLog(fd), q, x));
final TurboLog tf = new TurboLog(n);
ts.execute(new DoubleToFloatTimingTask(new TestLog(tf), q, x, xf));
ts.execute(new DoubleToFloatTimingTask(new TestFastLog(tf), q, x, xf));
ts.execute(new FloatTimingTask(new TestLog(tf), q, xf));
ts.execute(new FloatTimingTask(new TestFastLog(tf), q, xf));
ts.execute(new DoubleTimingTask(new TestLog(tf), q, x));
ts.execute(new DoubleTimingTask(new TestFastLog(tf), q, x));
final TurboLog2 tf2 = new TurboLog2(n);
ts.execute(new DoubleToFloatTimingTask(new TestLog(tf2), q, x, xf));
ts.execute(new DoubleToFloatTimingTask(new TestFastLog(tf2), q, x, xf));
ts.execute(new FloatTimingTask(new TestLog(tf2), q, xf));
ts.execute(new FloatTimingTask(new TestFastLog(tf2), q, xf));
ts.execute(new DoubleTimingTask(new TestLog(tf2), q, x));
ts.execute(new DoubleTimingTask(new TestFastLog(tf2), q, x));
// Slower as the look-up table is bigger
final FFastLog f1 = new FFastLog(n);
final DFastLog f2 = new DFastLog(n);
ts.execute(new FloatTimingTask(new TestLog(f1), q, xf));
ts.execute(new FloatTimingTask(new TestFastLog(f1), q, xf));
ts.execute(new DoubleTimingTask(new TestLog(f2), q, x));
ts.execute(new DoubleTimingTask(new TestFastLog(f2), q, x));
}
final int size = ts.getSize();
ts.repeat(size);
logger.info(ts.getReport(size));
}
use of uk.ac.sussex.gdsc.test.junit5.SpeedTag in project GDSC-SMLM by aherbert.
the class FastLogTest method canTestDoubleSpeed.
@SpeedTag
@SeededTest
void canTestDoubleSpeed(RandomSeed seed) {
// No assertions, this is just a report
Assumptions.assumeTrue(logger.isLoggable(Level.INFO));
Assumptions.assumeTrue(TestSettings.allow(TestComplexity.MEDIUM));
final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
final double[] values = new double[1000000];
for (int i = 0; i < values.length; i++) {
values[i] = nextUniformDouble(rng);
}
final TimingService ts = new TimingService(5);
ts.execute(new DoubleTimingTask(new TestLog(new MathLog()), 0, values));
ts.execute(new DoubleTimingTask(new TestLog(new FastMathLog()), 0, values));
// ts.execute(new DoubleTimingTask(new TestFastLog(tf3), 15, x));
for (final int q : new int[] { 11 }) {
final int n = 23 - q;
final IcsiFastLog fl = IcsiFastLog.create(n, DataType.DOUBLE);
ts.execute(new DoubleTimingTask(new TestLog(fl), q, values));
ts.execute(new DoubleTimingTask(new TestFastLog(fl), q, values));
final DFastLog df = new DFastLog(n);
// ts.execute(new DoubleTimingTask(new DFastLog_log2(fl), q, x));
// ts.execute(new DoubleTimingTask(new DTestFastLog2(fl), q, x));
ts.execute(new DoubleTimingTask(new TestLog(df), q, values));
ts.execute(new DoubleTimingTask(new TestFastLog(df), q, values));
final TurboLog tf = new TurboLog(n);
ts.execute(new DoubleTimingTask(new TestLog(tf), q, values));
ts.execute(new DoubleTimingTask(new TestFastLog(tf), q, values));
// Test same precision
final TurboLog2 tf2 = new TurboLog2(n - 1);
ts.execute(new DoubleTimingTask(new TestLog(tf2), q + 1, values));
ts.execute(new DoubleTimingTask(new TestFastLog(tf2), q + 1, values));
// // Min acceptable precision. This is usually the same speed
// // showing the precomputed table is optimally used for moderate n.
// ts.execute(new DoubleTimingTask(new TestLog(tf3), 15, x));
// ts.execute(new DoubleTimingTask(new TestFastLog(tf3), 15, x));
}
final int size = ts.getSize();
ts.repeat(size);
logger.info(ts.getReport(size));
}
use of uk.ac.sussex.gdsc.test.junit5.SpeedTag in project GDSC-SMLM by aherbert.
the class PoissonCalculatorTest method instanceMethodIsFaster.
@SpeedTag
@Test
void instanceMethodIsFaster() {
Assumptions.assumeTrue(TestSettings.allow(TestComplexity.MEDIUM));
final int n = 1000;
final int m = 10;
final double[] x = new double[n * m];
final double[] u = new double[x.length];
for (int i = 1, k = 0; i <= n; i++) {
final double testx = 0.1 * i;
// +/- 3SD of the expected
final double sd = 3 * Math.sqrt(testx);
final double min = Math.max(0.1, testx - sd);
final double max = testx + sd;
final double inc = (max - min) / (m - 1);
for (int j = 0; j < m; j++, k++) {
x[k] = testx;
u[k] = min + j * inc;
}
}
final double[] limits = MathUtils.limits(x);
logger.log(TestLogUtils.getRecord(LOG_LEVEL, "Speed test x-range: %f - %f", limits[0], limits[1]));
final TimingService ts = new TimingService(5);
final int[] loops = new int[] { 0, 1, 10 };
for (final int ll : loops) {
for (final int llr : loops) {
if (ll + llr == 0) {
continue;
}
ts.execute(new StaticPcTimingTask(x, u, ll, llr));
ts.execute(new FastPcTimingTask(x, u, ll, llr));
ts.execute(new FastLogPcTimingTask(x, u, ll, llr));
ts.execute(new InstancePcTimingTask(x, u, ll, llr));
}
}
final int size = ts.getSize();
ts.repeat(size);
if (logger.isLoggable(LOG_LEVEL)) {
logger.info(ts.getReport(size));
}
final int index = ts.getSize() - 1;
Assertions.assertTrue(ts.get(index).getMean() < ts.get(index - 1).getMean());
}
use of uk.ac.sussex.gdsc.test.junit5.SpeedTag in project GDSC-SMLM by aherbert.
the class GaussianFilterTest method floatFilterIsFasterThanDoubleFilter.
@SpeedTag
@SeededTest
void floatFilterIsFasterThanDoubleFilter(RandomSeed seed) {
Assumptions.assumeTrue(TestSettings.allow(TestComplexity.MEDIUM));
final UniformRandomProvider rg = RngUtils.create(seed.getSeed());
final float[][] data = new float[10][];
for (int i = 0; i < data.length; i++) {
data[i] = createData(rg, size, size);
}
final TimingService ts = new TimingService();
for (final double sigma : sigmas) {
ts.execute(new MyTimingTask(new FloatFilter(false), data, sigma));
ts.execute(new MyTimingTask(new DpFilter(false), data, sigma));
ts.execute(new MyTimingTask(new DoubleFilter(false), data, sigma));
}
final int size = ts.getSize();
ts.repeat();
if (logger.isLoggable(Level.INFO)) {
logger.info(ts.getReport(size));
}
final int n = size / sigmas.length;
for (int i = 0, j = size; i < sigmas.length; i++, j += n) {
for (int k = 1; k < n; k++) {
final TimingResult slow = ts.get(j + k);
final TimingResult fast = ts.get(j);
logger.log(TestLogUtils.getTimingRecord(slow, fast));
}
}
}
Aggregations