diff --git a/src/test/java/net/imglib2/img/cell/CellRandomAccessBenchmark.java b/src/test/java/net/imglib2/img/cell/CellRandomAccessBenchmark.java index 0178c9562..c155045fe 100644 --- a/src/test/java/net/imglib2/img/cell/CellRandomAccessBenchmark.java +++ b/src/test/java/net/imglib2/img/cell/CellRandomAccessBenchmark.java @@ -42,6 +42,7 @@ import net.imglib2.type.numeric.integer.IntType; import net.imglib2.util.BenchmarkHelper; import net.imglib2.util.IntervalIndexer; +import net.imglib2.view.IterableRandomAccessibleInterval; /** * TODO @@ -102,6 +103,19 @@ public void fillImage() } } + /** + * Fill intImg (a CellContainer with 40x40x40 cells) with data using flat + * array iteration order. + */ + public void fillImage2() + { + final Cursor< IntType > c = new IterableRandomAccessibleInterval<>( intImg ).cursor(); + for ( int i = 0; i < numValues; ++i ) + { + c.next().set( intData[ i ] ); + } + } + public void copyWithSourceIteration( final Img< IntType > srcImg, final Img< IntType > dstImg ) { final long[] pos = new long[ dimensions.length ]; @@ -122,50 +136,21 @@ public static void main( final String[] args ) randomAccessBenchmark.createSourceData(); System.out.println( "benchmarking fill" ); - BenchmarkHelper.benchmarkAndPrint( 50, true, new Runnable() - { - @Override - public void run() - { - randomAccessBenchmark.fillImage(); - } - } ); - randomAccessBenchmark.intData = null; + BenchmarkHelper.benchmarkAndPrint( 20, false, randomAccessBenchmark::fillImage ); + + System.out.println( "benchmarking fill 2" ); + BenchmarkHelper.benchmarkAndPrint( 20, false, randomAccessBenchmark::fillImage2 ); randomAccessBenchmark.intImgCopy = new CellImgFactory<>( new IntType(), 32 ).create( randomAccessBenchmark.dimensions ); System.out.println( "benchmarking copy to smaller" ); - BenchmarkHelper.benchmarkAndPrint( 20, false, new Runnable() - { - @Override - public void run() - { - randomAccessBenchmark.copyWithSourceIteration( randomAccessBenchmark.intImg, randomAccessBenchmark.intImgCopy ); - } - } ); - randomAccessBenchmark.intImgCopy = null; + BenchmarkHelper.benchmarkAndPrint( 20, false, () -> randomAccessBenchmark.copyWithSourceIteration( randomAccessBenchmark.intImg, randomAccessBenchmark.intImgCopy ) ); randomAccessBenchmark.intImgCopy = new CellImgFactory<>( new IntType(), 50 ).create( randomAccessBenchmark.dimensions ); System.out.println( "benchmarking copy to larger" ); - BenchmarkHelper.benchmarkAndPrint( 20, false, new Runnable() - { - @Override - public void run() - { - randomAccessBenchmark.copyWithSourceIteration( randomAccessBenchmark.intImg, randomAccessBenchmark.intImgCopy ); - } - } ); - randomAccessBenchmark.intImgCopy = null; + BenchmarkHelper.benchmarkAndPrint( 20, false, () -> randomAccessBenchmark.copyWithSourceIteration( randomAccessBenchmark.intImg, randomAccessBenchmark.intImgCopy ) ); randomAccessBenchmark.intImgCopy = new CellImgFactory<>( new IntType(), 32, 64, 16 ).create( randomAccessBenchmark.dimensions ); System.out.println( "benchmarking copy to mixed" ); - BenchmarkHelper.benchmarkAndPrint( 20, false, new Runnable() - { - @Override - public void run() - { - randomAccessBenchmark.copyWithSourceIteration( randomAccessBenchmark.intImg, randomAccessBenchmark.intImgCopy ); - } - } ); - randomAccessBenchmark.intImgCopy = null; + BenchmarkHelper.benchmarkAndPrint( 20, false, () -> randomAccessBenchmark.copyWithSourceIteration( randomAccessBenchmark.intImg, randomAccessBenchmark.intImgCopy ) ); } }