diff --git a/core-java-modules/core-java-perf-2/README.md b/core-java-modules/core-java-perf-2/README.md new file mode 100644 index 0000000000..5616cce48b --- /dev/null +++ b/core-java-modules/core-java-perf-2/README.md @@ -0,0 +1 @@ +## Relevant Articles diff --git a/core-java-modules/core-java-perf-2/pom.xml b/core-java-modules/core-java-perf-2/pom.xml new file mode 100644 index 0000000000..a9408ca385 --- /dev/null +++ b/core-java-modules/core-java-perf-2/pom.xml @@ -0,0 +1,16 @@ + + + 4.0.0 + core-java-perf-2 + core-java-perf-2 + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + + + \ No newline at end of file diff --git a/core-java-modules/core-java-perf-2/src/main/java/com/baeldung/highcpu/Application.java b/core-java-modules/core-java-perf-2/src/main/java/com/baeldung/highcpu/Application.java new file mode 100644 index 0000000000..82162406b3 --- /dev/null +++ b/core-java-modules/core-java-perf-2/src/main/java/com/baeldung/highcpu/Application.java @@ -0,0 +1,20 @@ +package com.baeldung.highcpu; + +import java.util.LinkedList; +import java.util.List; +import java.util.function.IntUnaryOperator; +import java.util.stream.IntStream; + +public class Application { + + static List generateList() { + return IntStream.range(0, 10000000).parallel().map(IntUnaryOperator.identity()).collect(LinkedList::new, List::add, List::addAll); + } + + public static void main(String[] args) { + List list = generateList(); + long start = System.nanoTime(); + int value = list.get(9500000); + System.out.printf("Found value %d in %d nanos\n", value, (System.nanoTime() - start)); + } +}