BAEL-4876: Add benchmark
This commit is contained in:
parent
b0ade9d58b
commit
bce6207f03
@ -27,6 +27,17 @@
|
|||||||
<version>${lombok.version}</version>
|
<version>${lombok.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjdk.jmh</groupId>
|
||||||
|
<artifactId>jmh-core</artifactId>
|
||||||
|
<version>${jmh-core.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjdk.jmh</groupId>
|
||||||
|
<artifactId>jmh-generator-annprocess</artifactId>
|
||||||
|
<version>${jmh-generator.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<!-- test scoped -->
|
<!-- test scoped -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.assertj</groupId>
|
<groupId>org.assertj</groupId>
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
package com.baeldung.streams.parallel;
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.Benchmark;
|
||||||
|
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||||
|
import org.openjdk.jmh.annotations.Mode;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
public class DifferentSourceSplitting {
|
||||||
|
|
||||||
|
private static final List<Integer> arrayListOfNumbers = new ArrayList<>();
|
||||||
|
private static final List<Integer> linkedListOfNumbers = new LinkedList<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
IntStream.rangeClosed(1, 100_000_000).forEach(i -> {
|
||||||
|
arrayListOfNumbers.add(i);
|
||||||
|
linkedListOfNumbers.add(i);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
org.openjdk.jmh.Main.main(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
public static void arrayListSequential() {
|
||||||
|
arrayListOfNumbers.stream().reduce(0, Integer::sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
public static void arrayListParallel() {
|
||||||
|
arrayListOfNumbers.parallelStream().reduce(0, Integer::sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
public static void linkedListSequential() {
|
||||||
|
linkedListOfNumbers.stream().reduce(0, Integer::sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
public static void linkedListParallel() {
|
||||||
|
linkedListOfNumbers.parallelStream().reduce(0, Integer::sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.baeldung.streams.parallel;
|
||||||
|
|
||||||
|
import org.openjdk.jmh.annotations.Benchmark;
|
||||||
|
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||||
|
import org.openjdk.jmh.annotations.Mode;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
public class SplittingCosts {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
org.openjdk.jmh.Main.main(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
public static void arrayListSequential() {
|
||||||
|
IntStream.rangeClosed(1, 1_000).reduce(0, Integer::sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
public static void arrayListParallel() {
|
||||||
|
IntStream.rangeClosed(1, 1_000).parallel().reduce(0, Integer::sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user