Benchmark Example - IntStream vs. For-Loop
- Java 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| .github/workflows | ||
| profile-results | ||
| src/main/java/com/soebes/benchmark/intstream | ||
| .gitignore | ||
| CODE_OF_CONDUCT.md | ||
| CODE_OF_CONDUCT_de.md | ||
| LICENSE.txt | ||
| pom.xml | ||
| README.adoc | ||
Comparing
var result = IntStream.range(0,1000).boxed().toList();
vs.
List<Integer> scores = new ArrayList<>();
for (int i = 0; i < 1_000_000; i++) {
scores.add(i);
}
State
-
Working on it.
Requirements
-
Maven 3.9+
-
JDK17+ (build and runtime.)
Running
mvn verify
java -jar target/intstream-1.0-SNAPSHOT.jar -prof gc:alloc=true;churn=true -prof jfr:dir=profile-results
Results
Raw Performance
Benchmark (range) Mode Cnt Score Error Units
BenchmarkIntStreamVsForLoop.benchForLoop 1000000 avgt 25 7326,380 ± 190,772 us/op
BenchmarkIntStreamVsForLoop.benchForLoop 10000000 avgt 25 131275,575 ± 1781,566 us/op
BenchmarkIntStreamVsForLoop.benchIntStream 1000000 avgt 25 2932,812 ± 22,721 us/op
BenchmarkIntStreamVsForLoop.benchIntStream 10000000 avgt 25 72963,084 ± 725,221 us/op
Memory allocation/ GC Rates
Benchmark (range) Mode Cnt Score Error Units
BenchmarkIntStreamVsForLoop.benchForLoop 100 avgt 25 0,260 ± 0,002 us/op
BenchmarkIntStreamVsForLoop.benchForLoop:gc.alloc.rate 100 avgt 25 5128,768 ± 35,258 MB/sec
BenchmarkIntStreamVsForLoop.benchForLoop:gc.alloc.rate.norm 100 avgt 25 1400,000 ± 0,001 B/op
BenchmarkIntStreamVsForLoop.benchForLoop:gc.count 100 avgt 25 1982,000 counts
BenchmarkIntStreamVsForLoop.benchForLoop:gc.time 100 avgt 25 1047,000 ms
BenchmarkIntStreamVsForLoop.benchIntStream 100 avgt 25 0,297 ± 0,002 us/op
BenchmarkIntStreamVsForLoop.benchIntStream:gc.alloc.rate 100 avgt 25 2027,990 ± 15,844 MB/sec
BenchmarkIntStreamVsForLoop.benchIntStream:gc.alloc.rate.norm 100 avgt 25 632,000 ± 0,001 B/op
BenchmarkIntStreamVsForLoop.benchIntStream:gc.count 100 avgt 25 846,000 counts
BenchmarkIntStreamVsForLoop.benchIntStream:gc.time 100 avgt 25 462,000 ms