@@ -0,0 +1,2904 @@
+package _3_reducing;%0A%0Aimport org.junit.Test;%0Aimport org.openjdk.jmh.annotations.Benchmark;%0Aimport org.openjdk.jmh.annotations.Level;%0Aimport org.openjdk.jmh.annotations.Mode;%0Aimport org.openjdk.jmh.annotations.Scope;%0Aimport org.openjdk.jmh.annotations.Setup;%0Aimport org.openjdk.jmh.annotations.State;%0Aimport org.openjdk.jmh.infra.Blackhole;%0Aimport org.openjdk.jmh.runner.Runner;%0Aimport org.openjdk.jmh.runner.options.Options;%0Aimport org.openjdk.jmh.runner.options.OptionsBuilder;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0Aimport java.util.concurrent.CopyOnWriteArrayList;%0Aimport java.util.concurrent.TimeUnit;%0Aimport java.util.stream.Collectors;%0Aimport java.util.stream.IntStream;%0A%0Apublic class ReduceBenchmarkTest %7B%0A    @Test%0A    public void launchBenchmark() throws Exception %7B%0A        Options opt = new OptionsBuilder()%0A                .include(this.getClass().getSimpleName())%0A                .mode(Mode.AverageTime)%0A                .timeUnit(TimeUnit.MILLISECONDS)%0A                .warmupIterations(5)%0A                .measurementIterations(5)%0A                .forks(1)%0A                .shouldFailOnError(true)%0A                .shouldDoGC(false)%0A                .build();%0A%0A        new Runner(opt).run();%0A    %7D%0A%0A    @State(Scope.Thread)%0A    public static class BenchmarkState %7B%0A        List%3CInteger%3E input;%0A        @Setup(Level.Trial)%0A%0A        public void%0A        initialize() %7B%0A            input = IntStream.iterate(0, i -%3E i + 1)%0A                    .limit(100_000)%0A                    .boxed()%0A                    .collect(Collectors.toList());%0A        %7D%0A    %7D%0A%0A    @Benchmark%0A    public void serialAddToList(BenchmarkState state, Blackhole bh) %7B%0A        List%3CInteger%3E list = new CopyOnWriteArrayList%3C%3E();%0A        state.input%0A                .stream()%0A                .forEach(list::add);%0A%0A        bh.consume(list);%0A    %7D%0A%0A    @Benchmark%0A    public void parallelAddToList(BenchmarkState state, Blackhole bh) %7B%0A        List%3CInteger%3E list = new CopyOnWriteArrayList%3C%3E();%0A        state.input%0A                .stream()%0A                .parallel()%0A                .forEach(list::add);%0A%0A        bh.consume(list);%0A    %7D%0A%0A    @Benchmark%0A    public void serialReduce(BenchmarkState state, Blackhole bh) %7B%0A        List%3CInteger%3E list = state.input.stream()%0A                .map(Arrays::asList)%0A                .reduce(new ArrayList%3C%3E(), ReduceBenchmarkTest::concat);%0A        bh.consume(list);%0A    %7D%0A%0A    @Benchmark%0A    public void parallelReduce(BenchmarkState state, Blackhole bh) %7B%0A        List%3CInteger%3E list = state.input.stream()%0A                .parallel()%0A                .map(Arrays::asList)%0A                .reduce(new ArrayList%3C%3E(), ReduceBenchmarkTest::concat);%0A        bh.consume(list);%0A    %7D%0A%0A    static %3CT%3E List%3CT%3E concat(List%3CT%3E first, List%3CT%3E second) %7B%0A        List%3CT%3E both = new ArrayList%3CT%3E(first);%0A        both.addAll(second);%0A        return both;%0A    %7D%0A%7D%0A

Introduce benchmarks of reduce operation