kotlinx-benchmark icon indicating copy to clipboard operation
kotlinx-benchmark copied to clipboard

How to benchmark jdk.incubator (jvm)

Open quickstep24 opened this issue 3 years ago • 5 comments
trafficstars

I am trying to benchmark code that uses jdk.incubator.vector methods, but this raises an error in :jvmBenchmarkGenerate:

Generation of JMH bytecode failed with 1errors:
  - Annotation generator had thrown the exception.
java.lang.NoClassDefFoundError: jdk/incubator/vector/VectorSpecies

A minimal benchmark code is

@State(Scope.Benchmark)
open class MyBenchmark {
    val species: VectorSpecies<Long> = LongVector.SPECIES_PREFERRED
    @Benchmark fun test() = species.length()
}

I have tried adding @Fork(jvmArgs = ["--add-modules", "jdk.incubator.vector"]) and also added to build.gradle.kts:

tasks.withType<JavaExec> {
    if (name == "jvmBenchmark") {
        jvmArgs(listOf("--add-modules", "jdk.incubator.vector"))
    }
}

but without success.

quickstep24 avatar May 05 '22 15:05 quickstep24

Hi, could you able to solve this issue (for multiplatform setup)?.. i am slo facing the same issue when using vector APIs with jdk 21.

sureshg avatar Jul 19 '23 07:07 sureshg

No, in the end I used conventional time measurement (after some warming-up loops). My test cases were simple Boolean operations on large bitsets. I could not identify a performance gain, so I went back to conventional code. However, results may depend on your CPU architecture and I used an older jdk version.

quickstep24 avatar Jul 19 '23 07:07 quickstep24

Thanks...eventually i could able to run with @Fork(value = 1, jvmArgsAppend = ["--add-modules=jdk.incubator.vector"]) and some kotlin mpp compileJava and test configurations . Wish the framework had builtin support to configure more JMH parameters instead of hardcoding it in the Benchmark tests.

Edit: sorry, no this is not working as expected :/

sureshg avatar Jul 19 '23 08:07 sureshg