Vinicius
02/23/2025, 2:56 PMVinicius
02/23/2025, 2:58 PMplugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.vanniktech.mavenPublish)
id("org.jetbrains.kotlinx.benchmark") version "0.4.13"
}
group = "mrvin.kql"
version = "0.1.0"
kotlin {
jvm()
sourceSets {
val jvmMain by getting
val jvmTest by getting {
dependencies {
implementation("org.xerial:sqlite-jdbc:3.49.0.0")
implementation("org.postgresql:postgresql:42.7.5")
implementation(kotlin("test"))
val kotlinBenchmarkVersion = "0.4.13"
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:$kotlinBenchmarkVersion")
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime-jvm:$kotlinBenchmarkVersion")
}
}
}
}
benchmark {
targets {
register("jvm")
}
configurations {
named("main") {
warmups = 20
iterations = 10
iterationTime = 3
iterationTimeUnit = "s"
}
}
}
benchmark test (copied from instruction)
@State(Scope.Benchmark)
open class MyBenchmark {
private val size = 10
private val list = ArrayList<Int>()
@Setup
fun prepare() {
for (i in 0..<size) {
list.add(i)
}
}
@TearDown
fun cleanup() {
list.clear()
}
@Benchmark
fun benchmarkMethod(): Int {
return list.sum()
}
}
the error im getting:
mrvin@fedora:~/kql$ ./gradlew kql jdbcjvmBenchmark
Reusing configuration cache.
> Task kql jdbcjvmBenchmark FAILED
Running 'main' benchmarks for 'jvm'
Error: Could not find or load main class kotlinx.benchmark.jvm.JvmBenchmarkRunnerKt
Caused by: java.lang.ClassNotFoundException: kotlinx.benchmark.jvm.JvmBenchmarkRunnerKt
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task 'kql jdbcjvmBenchmark'.
> Process 'command '/usr/lib/jvm/jdk-21-oracle-x64/bin/java'' finished with non-zero exit value 1
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
BUILD FAILED in 457ms
3 actionable tasks: 1 executed, 2 up-to-date
Configuration cache entry reused.Vinicius
02/23/2025, 3:07 PMVinicius
02/23/2025, 3:30 PMFilipp Zhinkin
02/24/2025, 5:04 PMbenchmarks {
targets {
register("jvmTest") // instead of "jvm"
}
}
However, it's more common to either put them into a separate source set (https://github.com/Kotlin/kotlinx-benchmark/blob/master/docs/separate-benchmark-source-set.md), or create a separate Gradle sub-project that'll host benchmarks in its main source set.Filipp Zhinkin
02/24/2025, 5:06 PMkotlinx-benchmark