Skip to content

Commit

Permalink
update CellRandomAccessBenchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
tpietzsch committed Jul 14, 2023
1 parent 03d986e commit 0f83262
Showing 1 changed file with 21 additions and 36 deletions.
57 changes: 21 additions & 36 deletions src/test/java/net/imglib2/img/cell/CellRandomAccessBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ];
Expand All @@ -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 ) );
}
}

0 comments on commit 0f83262

Please sign in to comment.