|
| 1 | +package net.imglib2.algorithm.localextrema; |
| 2 | + |
| 3 | +import net.imglib2.Point; |
| 4 | +import net.imglib2.RandomAccessibleInterval; |
| 5 | +import net.imglib2.algorithm.neighborhood.RectangleShape; |
| 6 | +import net.imglib2.parallel.Parallelization; |
| 7 | +import net.imglib2.test.RandomImgs; |
| 8 | +import net.imglib2.type.numeric.integer.IntType; |
| 9 | +import net.imglib2.view.Views; |
| 10 | +import org.openjdk.jmh.annotations.Benchmark; |
| 11 | +import org.openjdk.jmh.annotations.BenchmarkMode; |
| 12 | +import org.openjdk.jmh.annotations.Fork; |
| 13 | +import org.openjdk.jmh.annotations.Measurement; |
| 14 | +import org.openjdk.jmh.annotations.Mode; |
| 15 | +import org.openjdk.jmh.annotations.Scope; |
| 16 | +import org.openjdk.jmh.annotations.State; |
| 17 | +import org.openjdk.jmh.annotations.Warmup; |
| 18 | +import org.openjdk.jmh.runner.Runner; |
| 19 | +import org.openjdk.jmh.runner.RunnerException; |
| 20 | +import org.openjdk.jmh.runner.options.Options; |
| 21 | +import org.openjdk.jmh.runner.options.OptionsBuilder; |
| 22 | + |
| 23 | +import java.util.List; |
| 24 | +import java.util.concurrent.ExecutionException; |
| 25 | +import java.util.concurrent.ExecutorService; |
| 26 | +import java.util.concurrent.Executors; |
| 27 | +import java.util.concurrent.ForkJoinPool; |
| 28 | +import java.util.concurrent.TimeUnit; |
| 29 | +import java.util.concurrent.atomic.AtomicLong; |
| 30 | +import java.util.stream.Collectors; |
| 31 | +import java.util.stream.LongStream; |
| 32 | + |
| 33 | +/** |
| 34 | + * Demonstrates how to use {@link Parallelization} to execute a algorithm |
| 35 | + * single threaded / multi threaded .... |
| 36 | + * And shows the execution time. |
| 37 | + */ |
| 38 | +@Fork( 0 ) |
| 39 | +@Warmup( iterations = 10, time = 200, timeUnit = TimeUnit.MILLISECONDS ) |
| 40 | +@Measurement( iterations = 10, time = 200, timeUnit = TimeUnit.MILLISECONDS ) |
| 41 | +@State( Scope.Benchmark ) |
| 42 | +@BenchmarkMode( { Mode.AverageTime } ) |
| 43 | +public class LocalExtremaBenchmark |
| 44 | +{ |
| 45 | + |
| 46 | + private final RandomAccessibleInterval< IntType > image = RandomImgs.seed( 42 ).nextImage( new IntType(), 100, 100, 100 ); |
| 47 | + |
| 48 | + @Benchmark |
| 49 | + public List< Point > benchmark() throws ExecutionException, InterruptedException |
| 50 | + { |
| 51 | + LocalExtrema.LocalNeighborhoodCheck< Point, IntType > check = new LocalExtrema.MaximumCheck( new IntType( Integer.MIN_VALUE )); |
| 52 | + return LocalExtrema.findLocalExtrema( image, check, new RectangleShape( 5, true ) ); |
| 53 | + } |
| 54 | + |
| 55 | + public static void main( String... args ) throws RunnerException |
| 56 | + { |
| 57 | + Options options = new OptionsBuilder() |
| 58 | + .include( LocalExtremaBenchmark.class.getName() ) |
| 59 | + .build(); |
| 60 | + new Runner( options ).run(); |
| 61 | + } |
| 62 | +} |
0 commit comments