public static void main(final String[] args) { final int numRuns = 20; final boolean printIndividualTimes = false; final long[] dimensions = new long[] {200, 200, 200}; final Img<FloatType> img = ArrayImgs.floats(dimensions); final Random random = new Random(123914924); for (final FloatType t : img) t.set(random.nextFloat()); System.out.println("findLocalMaximaNeighborhood"); System.out.println("(using old LocalNeighborhoodCursor)"); BenchmarkHelper.benchmarkAndPrint( numRuns, printIndividualTimes, new Runnable() { @Override public void run() { findLocalMaximaNeighborhood(img); } }); System.out.println("findLocalMaximaNeighborhood2"); System.out.println("(using LocalNeighborhoodCursor2 by Bene and Tobias)"); BenchmarkHelper.benchmarkAndPrint( numRuns, printIndividualTimes, new Runnable() { @Override public void run() { findLocalMaximaNeighborhood2(img); } }); System.out.println("findLocalMaximaNeighborhood6"); System.out.println("(using RectangleShape)"); BenchmarkHelper.benchmarkAndPrint( numRuns, printIndividualTimes, new Runnable() { @Override public void run() { findLocalMaximaNeighborhood6(img); } }); final int n = findLocalMaximaNeighborhood(img); System.out.println(n); final int n2 = findLocalMaximaNeighborhood2(img); System.out.println(n2); final int n6 = findLocalMaximaNeighborhood6(img); System.out.println(n6); }
public static void benchmarkAndCompare( final int numRuns, final boolean individualRuns, final Runnable norm, final Runnable opt) { final ArrayList<Long> valuesNorm = BenchmarkHelper.benchmark(numRuns, norm); final ArrayList<Long> valuesOpt = BenchmarkHelper.benchmark(numRuns, opt); final long[] statsNorm = computeStats(valuesNorm); final long[] statsOpt = computeStats(valuesOpt); final long[] statsDiff = new long[] { (statsNorm[0] - statsOpt[0]), (statsNorm[1] - statsOpt[1]), (statsNorm[2] - statsOpt[2]) }; // print System.out.println("\t| Unoptimized \t| Optimized \t| Speedup Time \t| Speedup % \t|"); System.out.println( "Median\t|\t" + statsNorm[0] + "\t|\t" + statsOpt[0] + "\t| " + statsDiff[0] + "ms \t| " + ((int) (1000.0 / statsNorm[0] * statsDiff[0]) / 10.0) + "% \t|"); System.out.println( "Best\t|\t" + statsNorm[1] + "\t|\t" + statsOpt[1] + "\t| " + statsDiff[1] + "ms \t| " + ((int) (1000.0 / statsNorm[1] * statsDiff[1]) / 10.0) + "% \t|"); System.out.println( "Worst\t|\t" + statsNorm[2] + "\t|\t" + statsOpt[2] + "\t| " + statsDiff[2] + "ms \t| " + ((int) (1000.0 / statsNorm[2] * statsDiff[2]) / 10.0) + "% \t|"); System.out.println(); }