-gc true를 사용하는 Java 12 대 Java 8의 스트림 API에 대한 신비한 마이크로 벤치 마크 결과
복잡한 필터를 사용하거나 스트림에서 여러 필터를 사용하는 것의 차이점에 대한 조사의 일환으로 Java 12의 성능이 Java 8보다 훨씬 느립니다.
그 이상한 결과에 대한 설명이 있습니까? 내가 여기서 뭔가 놓친 건가요?
구성 :
자바 8
- OpenJDK 런타임 환경 (빌드 1.8.0_181-8u181-b13-2 ~ deb9u1-b13)
- OpenJDK 64 비트 서버 VM (빌드 25.181-b13, 혼합 모드)
자바 12
- OpenJDK 런타임 환경 (빌드 12 + 33)
- OpenJDK 64 비트 서버 VM (빌드 12 + 33, 혼합 모드, 공유)
VM 옵션 :
-XX:+UseG1GC
-server
-Xmx1024m
-Xms1024m
- CPU : 8 코어
JMH 처리량 결과 :
- 워밍업 : 10 회 반복, 각각 1 초
- 측정 : 10 회 반복, 각각 1 초
- 스레드 : 1 개의 스레드, 반복 동기화
- 단위 : ops / s
암호
스트림 + 복합 필터
public void complexFilter(ExecutionPlan plan, Blackhole blackhole) {
long count = plan.getDoubles()
.stream()
.filter(d -> d < Math.PI
&& d > Math.E
&& d != 3
&& d != 2)
.count();
blackhole.consume(count);
}
스트림 + 여러 필터
public void multipleFilters(ExecutionPlan plan, Blackhole blackhole) {
long count = plan.getDoubles()
.stream()
.filter(d -> d > Math.PI)
.filter(d -> d < Math.E)
.filter(d -> d != 3)
.filter(d -> d != 2)
.count();
blackhole.consume(count);
}
병렬 스트림 + 복합 필터
public void complexFilterParallel(ExecutionPlan plan, Blackhole blackhole) {
long count = plan.getDoubles()
.stream()
.parallel()
.filter(d -> d < Math.PI
&& d > Math.E
&& d != 3
&& d != 2)
.count();
blackhole.consume(count);
}
병렬 스트림 + 다중 필터
public void multipleFiltersParallel(ExecutionPlan plan, Blackhole blackhole) {
long count = plan.getDoubles()
.stream()
.parallel()
.filter(d -> d > Math.PI)
.filter(d -> d < Math.E)
.filter(d -> d != 3)
.filter(d -> d != 2)
.count();
blackhole.consume(count);
}
구식 자바 반복
public void oldFashionFilters(ExecutionPlan plan, Blackhole blackhole) {
long count = 0;
for (int i = 0; i < plan.getDoubles().size(); i++) {
if (plan.getDoubles().get(i) > Math.PI
&& plan.getDoubles().get(i) > Math.E
&& plan.getDoubles().get(i) != 3
&& plan.getDoubles().get(i) != 2) {
count = count + 1;
}
}
blackhole.consume(count);
}
docker 명령을 실행하여 직접 시도 할 수 있습니다.
Java 8의 경우 :
docker run -it volkodav / java-filter-benchmark : java8
Java 12의 경우 :
docker run -it volkodav / java-filter-benchmark : java12
소스 코드:
https://github.com/volkodavs/javafilters-benchmarks
도움을 주신 모든 분들, 특히 @Aleksey Shipilev에게 감사드립니다!
JMH 벤치 마크에 변경 사항을 적용하면 결과가 더욱 현실적으로 보입니다 (?)
변경 사항 :
벤치 마크 반복 전 / 후에 실행할 설정 방법을 변경합니다.
@Setup(Level.Invocation)
->@Setup(Level.Iteration)
반복 사이에 JMH 강제 GC를 중지합니다. 각 반복 전에 Full GC를 강제로 실행하면 GC 휴리스틱을 포기할 가능성이 높습니다. (c) Aleksey Shipilev
-gc true
->-gc false
참고 : 기본적으로 gc false입니다.
비교표
새로운 성능 벤치 마크에 따르면 Java 8에 비해 Java 12에서 성능 저하가 없습니다.
참고 : 이러한 변경 후 작은 어레이 크기에 대한 처리량 오류는 100 % 이상 크게 증가하여 큰 데이터 세트는 동일하게 유지됩니다.
원시 결과
자바 8
# Run complete. Total time: 04:36:29
Benchmark (arraySize) Mode Cnt Score Error Units
FilterBenchmark.complexFilter 10 thrpt 50 5947577.648 ± 257535.736 ops/s
FilterBenchmark.complexFilter 100 thrpt 50 3131081.555 ± 72868.963 ops/s
FilterBenchmark.complexFilter 1000 thrpt 50 489666.688 ± 6539.466 ops/s
FilterBenchmark.complexFilter 10000 thrpt 50 17297.424 ± 93.890 ops/s
FilterBenchmark.complexFilter 100000 thrpt 50 1398.702 ± 72.820 ops/s
FilterBenchmark.complexFilter 1000000 thrpt 50 81.309 ± 0.547 ops/s
FilterBenchmark.complexFilterParallel 10 thrpt 50 24515.743 ± 450.363 ops/s
FilterBenchmark.complexFilterParallel 100 thrpt 50 25584.773 ± 290.249 ops/s
FilterBenchmark.complexFilterParallel 1000 thrpt 50 24313.066 ± 425.817 ops/s
FilterBenchmark.complexFilterParallel 10000 thrpt 50 11909.085 ± 51.534 ops/s
FilterBenchmark.complexFilterParallel 100000 thrpt 50 3260.864 ± 522.565 ops/s
FilterBenchmark.complexFilterParallel 1000000 thrpt 50 406.297 ± 96.590 ops/s
FilterBenchmark.multipleFilters 10 thrpt 50 3785766.911 ± 27971.998 ops/s
FilterBenchmark.multipleFilters 100 thrpt 50 1806210.041 ± 11578.529 ops/s
FilterBenchmark.multipleFilters 1000 thrpt 50 211435.445 ± 28585.969 ops/s
FilterBenchmark.multipleFilters 10000 thrpt 50 12614.670 ± 370.086 ops/s
FilterBenchmark.multipleFilters 100000 thrpt 50 1228.127 ± 21.208 ops/s
FilterBenchmark.multipleFilters 1000000 thrpt 50 99.149 ± 1.370 ops/s
FilterBenchmark.multipleFiltersParallel 10 thrpt 50 23896.812 ± 255.117 ops/s
FilterBenchmark.multipleFiltersParallel 100 thrpt 50 25314.613 ± 169.724 ops/s
FilterBenchmark.multipleFiltersParallel 1000 thrpt 50 23113.388 ± 305.605 ops/s
FilterBenchmark.multipleFiltersParallel 10000 thrpt 50 12676.057 ± 119.555 ops/s
FilterBenchmark.multipleFiltersParallel 100000 thrpt 50 3373.367 ± 211.108 ops/s
FilterBenchmark.multipleFiltersParallel 1000000 thrpt 50 477.870 ± 70.878 ops/s
FilterBenchmark.oldFashionFilters 10 thrpt 50 45874144.758 ± 2210325.177 ops/s
FilterBenchmark.oldFashionFilters 100 thrpt 50 4902625.828 ± 60397.844 ops/s
FilterBenchmark.oldFashionFilters 1000 thrpt 50 662102.438 ± 5038.465 ops/s
FilterBenchmark.oldFashionFilters 10000 thrpt 50 29390.911 ± 257.311 ops/s
FilterBenchmark.oldFashionFilters 100000 thrpt 50 1999.032 ± 6.829 ops/s
FilterBenchmark.oldFashionFilters 1000000 thrpt 50 200.564 ± 1.695 ops/s
자바 12
# Run complete. Total time: 04:36:20
Benchmark (arraySize) Mode Cnt Score Error Units
FilterBenchmark.complexFilter 10 thrpt 50 10338525.553 ? 1677693.433 ops/s
FilterBenchmark.complexFilter 100 thrpt 50 4381301.188 ? 287299.598 ops/s
FilterBenchmark.complexFilter 1000 thrpt 50 607572.430 ? 9367.026 ops/s
FilterBenchmark.complexFilter 10000 thrpt 50 30643.286 ? 472.033 ops/s
FilterBenchmark.complexFilter 100000 thrpt 50 1450.341 ? 3.730 ops/s
FilterBenchmark.complexFilter 1000000 thrpt 50 138.996 ? 2.052 ops/s
FilterBenchmark.complexFilterParallel 10 thrpt 50 21289.444 ? 183.245 ops/s
FilterBenchmark.complexFilterParallel 100 thrpt 50 20105.239 ? 124.759 ops/s
FilterBenchmark.complexFilterParallel 1000 thrpt 50 19418.830 ? 141.664 ops/s
FilterBenchmark.complexFilterParallel 10000 thrpt 50 13874.585 ? 104.418 ops/s
FilterBenchmark.complexFilterParallel 100000 thrpt 50 5334.947 ? 25.452 ops/s
FilterBenchmark.complexFilterParallel 1000000 thrpt 50 781.046 ? 9.687 ops/s
FilterBenchmark.multipleFilters 10 thrpt 50 5460308.048 ? 478157.935 ops/s
FilterBenchmark.multipleFilters 100 thrpt 50 2227583.836 ? 113078.932 ops/s
FilterBenchmark.multipleFilters 1000 thrpt 50 287157.190 ? 1114.346 ops/s
FilterBenchmark.multipleFilters 10000 thrpt 50 16268.016 ? 704.735 ops/s
FilterBenchmark.multipleFilters 100000 thrpt 50 1531.516 ? 2.729 ops/s
FilterBenchmark.multipleFilters 1000000 thrpt 50 123.881 ? 1.525 ops/s
FilterBenchmark.multipleFiltersParallel 10 thrpt 50 20403.993 ? 147.247 ops/s
FilterBenchmark.multipleFiltersParallel 100 thrpt 50 19426.222 ? 96.979 ops/s
FilterBenchmark.multipleFiltersParallel 1000 thrpt 50 17692.433 ? 67.606 ops/s
FilterBenchmark.multipleFiltersParallel 10000 thrpt 50 12108.482 ? 34.500 ops/s
FilterBenchmark.multipleFiltersParallel 100000 thrpt 50 3782.756 ? 22.044 ops/s
FilterBenchmark.multipleFiltersParallel 1000000 thrpt 50 589.972 ? 71.448 ops/s
FilterBenchmark.oldFashionFilters 10 thrpt 50 41024334.062 ? 1374663.440 ops/s
FilterBenchmark.oldFashionFilters 100 thrpt 50 6011852.027 ? 246202.642 ops/s
FilterBenchmark.oldFashionFilters 1000 thrpt 50 553243.594 ? 2217.912 ops/s
FilterBenchmark.oldFashionFilters 10000 thrpt 50 29188.753 ? 580.958 ops/s
FilterBenchmark.oldFashionFilters 100000 thrpt 50 2061.738 ? 8.456 ops/s
FilterBenchmark.oldFashionFilters 1000000 thrpt 50 196.105 ? 3.203 ops/s
'Nice programing' 카테고리의 다른 글
iOS 9 용 Xcode 7에서 XPC 연결이 중단됨 (0) | 2021.01.08 |
---|---|
LLVM 프로필 오류 :“default.profraw”파일 쓰기 실패 : 권한이 거부되었습니다. (0) | 2021.01.08 |
Quartz로 iOS에서 PDF 하이퍼 링크 받기 (0) | 2021.01.08 |
HTML5와 호환되는 HTML 필터 (0) | 2021.01.08 |
epoll ()은 O (1)에서 작동합니까? (0) | 2021.01.08 |