【JMH】Kotlin-DSL로 JMH Gradle Plugin을 이용한 벤치마크를 움직일 때까지 【Kotlin】
12700 단어 jmhKotlin-DSLgradle.ktsgradleKotlin
me.champeau.gradle.jmh 0.5.2를 사용하는 경우 Windows에서 다음 문제가 발생할 수 있습니다.재빌드가 통과하지 못하거나 벤치마크를 중단해도 프로세스가 죽지 않는 등의 문제가 발생하는 경우
gradle jmh --no-daemon로 실행하십시오.【JMH】JMH Gradle Plugin은 Windows 10에서 정상적으로 동작하지 않는다 【Gradle】 - Qiita
JMH Gradle Plugin ( me.champeau.gradle.jmh )를 사용하여 JMH 벤치 마크를 움직이는 샘플을 소개합니다.전체 프로젝트는 다음 리포지토리로 올라갑니다.
프로젝트 초기화
프로젝트는 Intellij IDEA를 사용하여 다음과 같이 초기화되었습니다.
1. Kotlin DSL build script 와 Kotlin/JVM 에 체크를 하고, 그 이외는 제외한다

2. Name 및 GroupId를 적절하게 설정

다음은 초기화 직후의 build.gradle.kts입니다.
build.gradle.kts(변경 전)plugins {
kotlin("jvm") version "1.4.10"
}
group = "com.wrongwrong"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib"))
}
build.gradle.kts에 추가
플러그인과 라이브러리를 각각 추가합니다.
plugins {
kotlin("jvm") version "1.4.10"
+ id("me.champeau.gradle.jmh") version "0.5.2"
}
group = "com.wrongwrong"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib"))
+ implementation(group = "org.openjdk.jmh", name = "jmh-core", version = "1.25.2")
}
src / jmh에 groupId에 맞는 패키지 준비
플러그인 README에 설명되어 있습니다. 대로, JMH Gradle Plugin 에서는 src/jmh 부하에 벤치마크가 있다고 가정합니다.
또한 groupId에 맞는 패키지가 아니면 벤치마크가 제대로 작동하지 않습니다..
따라서, 이번은 group = "com.wrongwrong"로 하고 있기 (위해)때문에, 다음과 같은 디렉토리 구성을 할 필요가 있습니다 1 .

지금까지 설정을 한 다음 벤치마크 프로그램을 만들면 gradle jmh에서 실행할 수 있습니다.
벤치마크 추가 및 실행
간단한 벤치마크로서, 랜덤하게 생성한 2개의 BigDecimal를 더한 벤치마크를 실시해 보겠습니다.
이전 섹션에서 설명한 대로 패키지는 com.wrongwrong로 배치합니다.
package com.wrongwrong
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State
import java.math.BigDecimal
import java.util.concurrent.ThreadLocalRandom
// JMHのベンチマーク関連の内容は`open class`として定義する必要が有る
open class SampleBenchmark {
@State(Scope.Thread)
open class Input {
val a: BigDecimal = ThreadLocalRandom.current().nextDouble(MAX_VALUE).toBigDecimal()
val b: BigDecimal = ThreadLocalRandom.current().nextDouble(MAX_VALUE).toBigDecimal()
companion object {
private const val MAX_VALUE = 10000.0
}
}
@Benchmark
fun measureAdd(input: Input): BigDecimal = input.a + input.b
}
실행 결과
gradle jmh --no-daemon로 실행하면 실행 결과는 다음과 같습니다.
>gradle jmh --no-daemon
> Task :jmhRunBytecodeGenerator
...
# Warmup Iteration 1: UTING [5s]
> Task :jmh
# JMH version: 1.25
# VM version: JDK 1.8.0_241, Java HotSpot(TM) 64-Bit Server VM, 25.241-b07
# VM invoker: ...
# VM options: <none>
# Warmup: 5 iterations, 10 s each
# Measurement: 5 iterations, 10 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: com.wrongwrong.SampleBenchmark.measureAdd
# Run progress: 0.00% complete, ETA 00:08:20
# Fork: 1 of 5
123535010.934 ops/s
# Warmup Iteration 2: 123979727.401 ops/s
# Warmup Iteration 3: 134043974.533 ops/s
# Warmup Iteration 4: 132468842.044 ops/s
# Warmup Iteration 5: 133974102.654 ops/s
Iteration 1: 132268760.988 ops/s]
Iteration 2: 134172199.789 ops/s5s]
Iteration 3: 132371282.057 ops/s15s]
Iteration 4: 134146688.977 ops/s25s]
Iteration 5: 132281181.244 ops/s35s]
> Task :jmh
# Run progress: 20.00% complete, ETA 00:06:41
# Fork: 2 of 5
# Warmup Iteration 1: 123418709.334 ops/s
# Warmup Iteration 2: 123974249.446 ops/s
# Warmup Iteration 3: 133771169.311 ops/s
# Warmup Iteration 4: 132314587.092 ops/s
# Warmup Iteration 5: 133683533.888 ops/s
Iteration 1: 132386673.995 ops/s35s]
Iteration 2: 133889633.018 ops/s45s]
Iteration 3: 132351518.216 ops/s55s]
Iteration 4: 133984395.968 ops/s5s]
Iteration 5: 132359193.064 ops/s15s]
> Task :jmh
# Run progress: 40.00% complete, ETA 00:05:00
# Fork: 3 of 5
# Warmup Iteration 1: 121795245.919 ops/s
# Warmup Iteration 2: 122968957.404 ops/s
# Warmup Iteration 3: 120593363.112 ops/s
# Warmup Iteration 4: 119424298.673 ops/s
# Warmup Iteration 5: 120837849.959 ops/s
Iteration 1: 119527380.883 ops/s16s]
Iteration 2: 120882687.677 ops/s26s]
Iteration 3: 119529815.116 ops/s36s]
Iteration 4: 121002476.444 ops/s46s]
Iteration 5: 119398499.673 ops/s56s]
> Task :jmh
# Run progress: 60.00% complete, ETA 00:03:20
# Fork: 4 of 5
# Warmup Iteration 1: 123466577.825 ops/s
# Warmup Iteration 2: 123937997.676 ops/s
# Warmup Iteration 3: 134091612.535 ops/s
# Warmup Iteration 4: 132087687.539 ops/s
# Warmup Iteration 5: 134119188.708 ops/s
Iteration 1: 132480152.938 ops/s56s]
Iteration 2: 133977021.297 ops/s6s]
Iteration 3: 132406987.113 ops/s16s]
Iteration 4: 134015243.441 ops/s26s]
Iteration 5: 132330706.552 ops/s36s]
> Task :jmh
# Run progress: 80.00% complete, ETA 00:01:40
# Fork: 5 of 5
# Warmup Iteration 1: 123306007.683 ops/s
# Warmup Iteration 2: 123730067.037 ops/s
# Warmup Iteration 3: 134053833.907 ops/s
# Warmup Iteration 4: 132625906.692 ops/s
# Warmup Iteration 5: 133897507.424 ops/s
Iteration 1: 132634681.882 ops/s36s]
Iteration 2: 134281816.570 ops/s46s]
Iteration 3: 132618358.352 ops/s56s]
Iteration 4: 134060049.422 ops/s6s]
Iteration 5: 132324371.611 ops/s16s]
> Task :jmh
Result "com.wrongwrong.SampleBenchmark.measureAdd":
130467271.051 ±(99.9%) 4022370.483 ops/s [Average]
(min, avg, max) = (119398499.673, 130467271.051, 134281816.570), stdev = 5369749.514
CI (99.9%): [126444900.569, 134489641.534] (assumes normal distribution)
# Run complete. Total time: 00:08:21
REMEMBER: The numbers below are just data. To gain reusable insights, you need to follow up on
why the numbers are the way they are. Use profilers (see -prof, -lprof), design factorial
experiments, perform baseline and negative tests that provide experimental control, make sure
the benchmarking environment is safe on JVM/OS/HW level, ask for reviews from the domain experts.
Do not assume the numbers tell you what you want them to tell.
Benchmark Mode Cnt Score Error Units
SampleBenchmark.measureAdd thrpt 25 130467271.051 ± 4022370.483 ops/s
Benchmark result is saved to ...
설정 등을 망치면 이 한계가 아니라고 생각합니다만, 이번은 간단을 위해 접하지 않습니다. ↩
Reference
이 문제에 관하여(【JMH】Kotlin-DSL로 JMH Gradle Plugin을 이용한 벤치마크를 움직일 때까지 【Kotlin】), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/wrongwrong/items/33be384c514db3282e2f
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
plugins {
kotlin("jvm") version "1.4.10"
}
group = "com.wrongwrong"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib"))
}
플러그인과 라이브러리를 각각 추가합니다.
plugins {
kotlin("jvm") version "1.4.10"
+ id("me.champeau.gradle.jmh") version "0.5.2"
}
group = "com.wrongwrong"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib"))
+ implementation(group = "org.openjdk.jmh", name = "jmh-core", version = "1.25.2")
}
src / jmh에 groupId에 맞는 패키지 준비
플러그인 README에 설명되어 있습니다. 대로, JMH Gradle Plugin 에서는 src/jmh 부하에 벤치마크가 있다고 가정합니다.
또한 groupId에 맞는 패키지가 아니면 벤치마크가 제대로 작동하지 않습니다..
따라서, 이번은 group = "com.wrongwrong"로 하고 있기 (위해)때문에, 다음과 같은 디렉토리 구성을 할 필요가 있습니다 1 .

지금까지 설정을 한 다음 벤치마크 프로그램을 만들면 gradle jmh에서 실행할 수 있습니다.
벤치마크 추가 및 실행
간단한 벤치마크로서, 랜덤하게 생성한 2개의 BigDecimal를 더한 벤치마크를 실시해 보겠습니다.
이전 섹션에서 설명한 대로 패키지는 com.wrongwrong로 배치합니다.
package com.wrongwrong
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State
import java.math.BigDecimal
import java.util.concurrent.ThreadLocalRandom
// JMHのベンチマーク関連の内容は`open class`として定義する必要が有る
open class SampleBenchmark {
@State(Scope.Thread)
open class Input {
val a: BigDecimal = ThreadLocalRandom.current().nextDouble(MAX_VALUE).toBigDecimal()
val b: BigDecimal = ThreadLocalRandom.current().nextDouble(MAX_VALUE).toBigDecimal()
companion object {
private const val MAX_VALUE = 10000.0
}
}
@Benchmark
fun measureAdd(input: Input): BigDecimal = input.a + input.b
}
실행 결과
gradle jmh --no-daemon로 실행하면 실행 결과는 다음과 같습니다.
>gradle jmh --no-daemon
> Task :jmhRunBytecodeGenerator
...
# Warmup Iteration 1: UTING [5s]
> Task :jmh
# JMH version: 1.25
# VM version: JDK 1.8.0_241, Java HotSpot(TM) 64-Bit Server VM, 25.241-b07
# VM invoker: ...
# VM options: <none>
# Warmup: 5 iterations, 10 s each
# Measurement: 5 iterations, 10 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: com.wrongwrong.SampleBenchmark.measureAdd
# Run progress: 0.00% complete, ETA 00:08:20
# Fork: 1 of 5
123535010.934 ops/s
# Warmup Iteration 2: 123979727.401 ops/s
# Warmup Iteration 3: 134043974.533 ops/s
# Warmup Iteration 4: 132468842.044 ops/s
# Warmup Iteration 5: 133974102.654 ops/s
Iteration 1: 132268760.988 ops/s]
Iteration 2: 134172199.789 ops/s5s]
Iteration 3: 132371282.057 ops/s15s]
Iteration 4: 134146688.977 ops/s25s]
Iteration 5: 132281181.244 ops/s35s]
> Task :jmh
# Run progress: 20.00% complete, ETA 00:06:41
# Fork: 2 of 5
# Warmup Iteration 1: 123418709.334 ops/s
# Warmup Iteration 2: 123974249.446 ops/s
# Warmup Iteration 3: 133771169.311 ops/s
# Warmup Iteration 4: 132314587.092 ops/s
# Warmup Iteration 5: 133683533.888 ops/s
Iteration 1: 132386673.995 ops/s35s]
Iteration 2: 133889633.018 ops/s45s]
Iteration 3: 132351518.216 ops/s55s]
Iteration 4: 133984395.968 ops/s5s]
Iteration 5: 132359193.064 ops/s15s]
> Task :jmh
# Run progress: 40.00% complete, ETA 00:05:00
# Fork: 3 of 5
# Warmup Iteration 1: 121795245.919 ops/s
# Warmup Iteration 2: 122968957.404 ops/s
# Warmup Iteration 3: 120593363.112 ops/s
# Warmup Iteration 4: 119424298.673 ops/s
# Warmup Iteration 5: 120837849.959 ops/s
Iteration 1: 119527380.883 ops/s16s]
Iteration 2: 120882687.677 ops/s26s]
Iteration 3: 119529815.116 ops/s36s]
Iteration 4: 121002476.444 ops/s46s]
Iteration 5: 119398499.673 ops/s56s]
> Task :jmh
# Run progress: 60.00% complete, ETA 00:03:20
# Fork: 4 of 5
# Warmup Iteration 1: 123466577.825 ops/s
# Warmup Iteration 2: 123937997.676 ops/s
# Warmup Iteration 3: 134091612.535 ops/s
# Warmup Iteration 4: 132087687.539 ops/s
# Warmup Iteration 5: 134119188.708 ops/s
Iteration 1: 132480152.938 ops/s56s]
Iteration 2: 133977021.297 ops/s6s]
Iteration 3: 132406987.113 ops/s16s]
Iteration 4: 134015243.441 ops/s26s]
Iteration 5: 132330706.552 ops/s36s]
> Task :jmh
# Run progress: 80.00% complete, ETA 00:01:40
# Fork: 5 of 5
# Warmup Iteration 1: 123306007.683 ops/s
# Warmup Iteration 2: 123730067.037 ops/s
# Warmup Iteration 3: 134053833.907 ops/s
# Warmup Iteration 4: 132625906.692 ops/s
# Warmup Iteration 5: 133897507.424 ops/s
Iteration 1: 132634681.882 ops/s36s]
Iteration 2: 134281816.570 ops/s46s]
Iteration 3: 132618358.352 ops/s56s]
Iteration 4: 134060049.422 ops/s6s]
Iteration 5: 132324371.611 ops/s16s]
> Task :jmh
Result "com.wrongwrong.SampleBenchmark.measureAdd":
130467271.051 ±(99.9%) 4022370.483 ops/s [Average]
(min, avg, max) = (119398499.673, 130467271.051, 134281816.570), stdev = 5369749.514
CI (99.9%): [126444900.569, 134489641.534] (assumes normal distribution)
# Run complete. Total time: 00:08:21
REMEMBER: The numbers below are just data. To gain reusable insights, you need to follow up on
why the numbers are the way they are. Use profilers (see -prof, -lprof), design factorial
experiments, perform baseline and negative tests that provide experimental control, make sure
the benchmarking environment is safe on JVM/OS/HW level, ask for reviews from the domain experts.
Do not assume the numbers tell you what you want them to tell.
Benchmark Mode Cnt Score Error Units
SampleBenchmark.measureAdd thrpt 25 130467271.051 ± 4022370.483 ops/s
Benchmark result is saved to ...
설정 등을 망치면 이 한계가 아니라고 생각합니다만, 이번은 간단을 위해 접하지 않습니다. ↩
Reference
이 문제에 관하여(【JMH】Kotlin-DSL로 JMH Gradle Plugin을 이용한 벤치마크를 움직일 때까지 【Kotlin】), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/wrongwrong/items/33be384c514db3282e2f
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
간단한 벤치마크로서, 랜덤하게 생성한 2개의
BigDecimal를 더한 벤치마크를 실시해 보겠습니다.이전 섹션에서 설명한 대로 패키지는
com.wrongwrong로 배치합니다.package com.wrongwrong
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State
import java.math.BigDecimal
import java.util.concurrent.ThreadLocalRandom
// JMHのベンチマーク関連の内容は`open class`として定義する必要が有る
open class SampleBenchmark {
@State(Scope.Thread)
open class Input {
val a: BigDecimal = ThreadLocalRandom.current().nextDouble(MAX_VALUE).toBigDecimal()
val b: BigDecimal = ThreadLocalRandom.current().nextDouble(MAX_VALUE).toBigDecimal()
companion object {
private const val MAX_VALUE = 10000.0
}
}
@Benchmark
fun measureAdd(input: Input): BigDecimal = input.a + input.b
}
실행 결과
gradle jmh --no-daemon로 실행하면 실행 결과는 다음과 같습니다.>gradle jmh --no-daemon
> Task :jmhRunBytecodeGenerator
...
# Warmup Iteration 1: UTING [5s]
> Task :jmh
# JMH version: 1.25
# VM version: JDK 1.8.0_241, Java HotSpot(TM) 64-Bit Server VM, 25.241-b07
# VM invoker: ...
# VM options: <none>
# Warmup: 5 iterations, 10 s each
# Measurement: 5 iterations, 10 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Throughput, ops/time
# Benchmark: com.wrongwrong.SampleBenchmark.measureAdd
# Run progress: 0.00% complete, ETA 00:08:20
# Fork: 1 of 5
123535010.934 ops/s
# Warmup Iteration 2: 123979727.401 ops/s
# Warmup Iteration 3: 134043974.533 ops/s
# Warmup Iteration 4: 132468842.044 ops/s
# Warmup Iteration 5: 133974102.654 ops/s
Iteration 1: 132268760.988 ops/s]
Iteration 2: 134172199.789 ops/s5s]
Iteration 3: 132371282.057 ops/s15s]
Iteration 4: 134146688.977 ops/s25s]
Iteration 5: 132281181.244 ops/s35s]
> Task :jmh
# Run progress: 20.00% complete, ETA 00:06:41
# Fork: 2 of 5
# Warmup Iteration 1: 123418709.334 ops/s
# Warmup Iteration 2: 123974249.446 ops/s
# Warmup Iteration 3: 133771169.311 ops/s
# Warmup Iteration 4: 132314587.092 ops/s
# Warmup Iteration 5: 133683533.888 ops/s
Iteration 1: 132386673.995 ops/s35s]
Iteration 2: 133889633.018 ops/s45s]
Iteration 3: 132351518.216 ops/s55s]
Iteration 4: 133984395.968 ops/s5s]
Iteration 5: 132359193.064 ops/s15s]
> Task :jmh
# Run progress: 40.00% complete, ETA 00:05:00
# Fork: 3 of 5
# Warmup Iteration 1: 121795245.919 ops/s
# Warmup Iteration 2: 122968957.404 ops/s
# Warmup Iteration 3: 120593363.112 ops/s
# Warmup Iteration 4: 119424298.673 ops/s
# Warmup Iteration 5: 120837849.959 ops/s
Iteration 1: 119527380.883 ops/s16s]
Iteration 2: 120882687.677 ops/s26s]
Iteration 3: 119529815.116 ops/s36s]
Iteration 4: 121002476.444 ops/s46s]
Iteration 5: 119398499.673 ops/s56s]
> Task :jmh
# Run progress: 60.00% complete, ETA 00:03:20
# Fork: 4 of 5
# Warmup Iteration 1: 123466577.825 ops/s
# Warmup Iteration 2: 123937997.676 ops/s
# Warmup Iteration 3: 134091612.535 ops/s
# Warmup Iteration 4: 132087687.539 ops/s
# Warmup Iteration 5: 134119188.708 ops/s
Iteration 1: 132480152.938 ops/s56s]
Iteration 2: 133977021.297 ops/s6s]
Iteration 3: 132406987.113 ops/s16s]
Iteration 4: 134015243.441 ops/s26s]
Iteration 5: 132330706.552 ops/s36s]
> Task :jmh
# Run progress: 80.00% complete, ETA 00:01:40
# Fork: 5 of 5
# Warmup Iteration 1: 123306007.683 ops/s
# Warmup Iteration 2: 123730067.037 ops/s
# Warmup Iteration 3: 134053833.907 ops/s
# Warmup Iteration 4: 132625906.692 ops/s
# Warmup Iteration 5: 133897507.424 ops/s
Iteration 1: 132634681.882 ops/s36s]
Iteration 2: 134281816.570 ops/s46s]
Iteration 3: 132618358.352 ops/s56s]
Iteration 4: 134060049.422 ops/s6s]
Iteration 5: 132324371.611 ops/s16s]
> Task :jmh
Result "com.wrongwrong.SampleBenchmark.measureAdd":
130467271.051 ±(99.9%) 4022370.483 ops/s [Average]
(min, avg, max) = (119398499.673, 130467271.051, 134281816.570), stdev = 5369749.514
CI (99.9%): [126444900.569, 134489641.534] (assumes normal distribution)
# Run complete. Total time: 00:08:21
REMEMBER: The numbers below are just data. To gain reusable insights, you need to follow up on
why the numbers are the way they are. Use profilers (see -prof, -lprof), design factorial
experiments, perform baseline and negative tests that provide experimental control, make sure
the benchmarking environment is safe on JVM/OS/HW level, ask for reviews from the domain experts.
Do not assume the numbers tell you what you want them to tell.
Benchmark Mode Cnt Score Error Units
SampleBenchmark.measureAdd thrpt 25 130467271.051 ± 4022370.483 ops/s
Benchmark result is saved to ...
설정 등을 망치면 이 한계가 아니라고 생각합니다만, 이번은 간단을 위해 접하지 않습니다. ↩
Reference
이 문제에 관하여(【JMH】Kotlin-DSL로 JMH Gradle Plugin을 이용한 벤치마크를 움직일 때까지 【Kotlin】), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/wrongwrong/items/33be384c514db3282e2f텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)