33import net .imglib2 .RandomAccess ;
44import net .imglib2 .RandomAccessible ;
55import net .imglib2 .algorithm .convolution .fast_gauss .FastGaussConvolverRealType ;
6+ import net .imglib2 .algorithm .convolution .kernel .ConvolverNativeType ;
7+ import net .imglib2 .algorithm .convolution .kernel .ConvolverNumericType ;
8+ import net .imglib2 .algorithm .convolution .kernel .FloatConvolverRealType ;
69import net .imglib2 .algorithm .convolution .kernel .Kernel1D ;
710import net .imglib2 .algorithm .convolution .kernel .KernelConvolverFactory ;
8- import net .imglib2 .algorithm .gauss3 .DoubleConvolverRealType ;
11+ import net .imglib2 .algorithm .convolution .kernel .DoubleConvolverRealType ;
12+ import net .imglib2 .algorithm .gauss3 .ConvolverFactory ;
913import net .imglib2 .algorithm .gauss3 .Gauss3 ;
1014import net .imglib2 .img .Img ;
1115import net .imglib2 .img .array .ArrayImgs ;
2529public class ConvolverBenchmark
2630{
2731
28- private int d = 2 ;
32+ private final int d = 2 ;
2933
30- private long lineLength = 1000 ;
34+ private final long lineLength = 1000 ;
3135
32- private double sigma = 2.0 ;
36+ private final double sigma = 2.0 ;
3337
34- private long [] dims = { 10 , 10 , lineLength };
38+ private final long [] dims = { 10 , 10 , lineLength };
3539
36- RandomAccessible < DoubleType > inImage = Views .extendBorder ( ArrayImgs .doubles ( dims ) );
40+ private final RandomAccessible < DoubleType > inImage = Views .extendBorder ( ArrayImgs .doubles ( dims ) );
3741
38- Img < DoubleType > outImage = ArrayImgs .doubles ( dims );
42+ private final Img < DoubleType > outImage = ArrayImgs .doubles ( dims );
3943
40- double [] halfKernel = Gauss3 .halfkernels ( new double [] { sigma } )[ 0 ];
44+ private final double [] halfKernel = Gauss3 .halfkernels ( new double [] { sigma } )[ 0 ];
45+
46+ private final Kernel1D kernel = Kernel1D .symmetric ( halfKernel );
4147
4248 @ Benchmark
4349 public void asymmetricKernelConvolver ()
4450 {
45- LineConvolverFactory < NumericType < ? > > assymetricConvolver = new KernelConvolverFactory ( Kernel1D . symmetric ( halfKernel ) );
46- Runnable runnable = assymetricConvolver .getConvolver ( in (), out (), d , lineLength );
51+ LineConvolverFactory < NumericType < ? > > assymetricConvolver = new KernelConvolverFactory ( kernel );
52+ final Runnable runnable = assymetricConvolver .getConvolver ( in (), out (), d , lineLength );
4753 runnable .run ();
4854 }
4955
5056 @ Benchmark
5157 public void symmetricKernelConvolver ()
5258 {
53- Runnable runnable = DoubleConvolverRealType .< DoubleType , DoubleType >factory ().create ( halfKernel , in (), out (), d , lineLength );
59+ final ConvolverFactory < DoubleType , DoubleType > factory = net .imglib2 .algorithm .gauss3 .DoubleConvolverRealType .< DoubleType , DoubleType >factory ();
60+ final Runnable runnable = factory .create ( halfKernel , in (), out (), d , lineLength );
61+ runnable .run ();
62+ }
63+
64+ @ Benchmark
65+ public void asymmetricDoubleConvolver ()
66+ {
67+ final Runnable runnable = new DoubleConvolverRealType ( kernel , in (), out (), d , lineLength );
68+ runnable .run ();
69+ }
70+
71+ @ Benchmark
72+ public void asymmetricFloatConvolver ()
73+ {
74+ final Runnable runnable = new FloatConvolverRealType ( kernel , in (), out (), d , lineLength );
75+ runnable .run ();
76+ }
77+
78+ @ Benchmark
79+ public void asymmetricNativeConvolver ()
80+ {
81+ final Runnable runnable = new ConvolverNativeType <>( kernel , in (), out (), d , lineLength );
82+ runnable .run ();
83+ }
84+
85+ @ Benchmark
86+ public void asymmetricNumericConvolve ()
87+ {
88+ final Runnable runnable = new ConvolverNumericType <>( kernel , in (), out (), d , lineLength );
5489 runnable .run ();
5590 }
5691
@@ -77,7 +112,7 @@ public static void main( String[] args ) throws RunnerException
77112 Options opt = new OptionsBuilder ()
78113 .include ( ConvolverBenchmark .class .getSimpleName () )
79114 .forks ( 0 )
80- .warmupIterations ( 4 )
115+ .warmupIterations ( 8 )
81116 .measurementIterations ( 8 )
82117 .warmupTime ( TimeValue .milliseconds ( 100 ) )
83118 .measurementTime ( TimeValue .milliseconds ( 100 ) )
0 commit comments