For Kotlin/JVM projects, you can isolate benchmarks by creating a custom source set and associating its compilation with your main or test compilation. This enables benchmarks to access internal APIs and reuse test code.
Step 1: Define the source set
Create a new source set named benchmark.
Step 2: Associate compilations
Associate the benchmark compilation with the main compilation (or test if you want to reuse test code) to allow access to internal APIs and dependency propagation.
Step 3: Register the benchmark target
Register the source set with the benchmark extension so the tool knows where to find and execute benchmarks.
Step 4: Add benchmark code
Place your benchmark code into the newly created benchmark source set.
// build.gradle.kts
sourceSets {
create("benchmark")
}
kotlin {
target {
compilations.getByName("benchmark")
.associateWith(compilations.getByName("main"))
}
}
benchmark {
targets {
register("benchmark")
}
}