kotlinx-benchmark
kotlinx-benchmark copied to clipboard
Onboarding feedback
It wasn't easy to get this working in JVM project :(
Adding a plugin and runtime library wasn't enough for JHM annotations to resolve
id("org.jetbrains.kotlinx.benchmark") version "0.4.4"
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime-jvm:0.4.4")
So i tried to add JHM explicitly, picked the latest version
implementation("org.openjdk.jmh:jmh-core:1.35")
Then i followed README and came up with this
benchmark {
targets {
register("main")
}
configurations {
val main by getting { // main configuration is created automatically, but you can change its defaults
warmups = 20 // number of warmup iterations
iterations = 10 // number of iterations
iterationTime = 3 // time in seconds per iteration
}
}
}
copy-pasted a sample benchmark from https://github.com/Kotlin/kotlinx-benchmark/tree/master/examples/kotlin
But got this error
/home/nikitak/IdeaProjects/pelagie/build/benchmarks/main/sources/org/generated/TestBenchmark_sqrtBenchmark_jmhTest.java:129: error: incompatible types: possible lossy conversion from double to long
I checked example once again and found that JHM version is specified inside the target https://github.com/Kotlin/kotlinx-benchmark/blob/master/examples/kotlin/build.gradle
benchmark {
// Setup configurations
targets {
// This one matches sourceSet name above
register("benchmarks") {
jmhVersion = "1.21"
}
}
}
I changed target configuration and commented out explicit JHM dependency and now everything is working
register("main") {
val a: BenchmarkTarget = this as kotlinx.benchmark.gradle.JvmBenchmarkTarget
jmhVersion = "1.21"
}
But actually i can just leave it as:
register("main")
So the problem is that for library to resolve i also had to register a target! I didn't think about it, tried to fix resolve another way and ran into a problem with newer versions of JHM being incompatible with generated code =( I tried to downgrade JHM to 1.27, but it also didn't work
Another pain point was that default build script language for Kotlin project is, well, Kotlin, but all examples are in Groovy.
Thanks!
@qurbonzoda please take it into account
Hi @koperagen,
Thanks for the feedback! Since your report, we have significantly improved the documentation. Specifically, for setting up benchmarks in a JVM project, we have a separate guide available here. Some other aspects still need improvement, though, e.g., sample projects. We have a separate issue for tracking this activity: https://github.com/Kotlin/kotlinx-benchmark/issues/183