1- import kotlinx.benchmark.gradle.JsBenchmarksExecutor
1+ @file:OptIn(ExperimentalWasmDsl ::class )
2+
3+ import kotlinx.benchmark.gradle.*
4+ import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
5+
26
37plugins {
4- id ' org.jetbrains. kotlin. multiplatform'
5- id ' org.jetbrains. kotlin. plugin.allopen' version " 2.0.20"
6- id ' org.jetbrains.kotlinx.benchmark'
8+ kotlin( " multiplatform" )
9+ kotlin( " plugin.allopen" ) version " 2.0.20"
10+ id( " org.jetbrains.kotlinx.benchmark" )
711}
812
9- // how to apply plugin to a specific source set?
1013allOpen {
1114 annotation(" org.openjdk.jmh.annotations.State" )
1215}
1316
1417kotlin {
1518 jvm {
16- compilations. create(' benchmark' ) { associateWith(compilations. main) }
19+ compilations.create(" benchmark" ) { associateWith(this @jvm. compilations.getByName( " main" ) ) }
1720 }
1821 js {
1922 nodejs()
20- compilations. create(" defaultExecutor" ) { associateWith(compilations. main) }
21- compilations. create(" builtInExecutor" ) { associateWith(compilations. main) }
23+ val mainCompilation = compilations.getByName(" main" )
24+ compilations.create(" defaultExecutor" ) { associateWith(mainCompilation) }
25+ compilations.create(" builtInExecutor" ) { associateWith(mainCompilation) }
2226 }
2327 wasmJs { nodejs() }
2428
@@ -33,17 +37,22 @@ kotlin {
3337 sourceSets {
3438 commonMain {
3539 dependencies {
36- implementation project(" :kotlinx-benchmark-runtime" )
40+ implementation( project(" :kotlinx-benchmark-runtime" ) )
3741 }
3842 }
3943
4044 jvmMain {}
4145
4246 wasmJsMain {}
4347
44- jsMain {
45- jsDefaultExecutor. dependsOn(it)
46- jsBuiltInExecutor. dependsOn(it)
48+ val jsMain by getting
49+
50+ getByName(" jsDefaultExecutor" ) {
51+ dependsOn(jsMain)
52+ }
53+
54+ getByName(" jsBuiltInExecutor" ) {
55+ dependsOn(jsMain)
4756 }
4857
4958 nativeMain {}
@@ -53,15 +62,15 @@ kotlin {
5362// Configure benchmark
5463benchmark {
5564 configurations {
56- main { // --> jvmBenchmark, jsBenchmark, < native target> Benchmark , benchmark
65+ named( " main" ) { // --> jvmBenchmark, jsBenchmark, <native target>Benchmark, benchmark
5766 iterations = 5 // number of iterations
5867 iterationTime = 300
5968 iterationTimeUnit = " ms"
6069 advanced(" jvmForks" , 3 )
6170 advanced(" jsUseBridge" , true )
6271 }
6372
64- params {
73+ create( " params" ) {
6574 iterations = 5 // number of iterations
6675 iterationTime = 300
6776 iterationTimeUnit = " ms"
@@ -70,7 +79,7 @@ benchmark {
7079 param(" unused" , 6 , 9 )
7180 }
7281
73- fast { // --> jvmFastBenchmark, jsFastBenchmark, < native target> FastBenchmark , fastBenchmark
82+ create( " fast" ) { // --> jvmFastBenchmark, jsFastBenchmark, <native target>FastBenchmark, fastBenchmark
7483 include(" Common" )
7584 exclude(" long" )
7685 iterations = 5
@@ -79,7 +88,7 @@ benchmark {
7988 advanced(" nativeGCAfterIteration" , true )
8089 }
8190
82- csv {
91+ create( " csv" ) {
8392 include(" Common" )
8493 exclude(" long" )
8594 iterations = 1
@@ -88,7 +97,7 @@ benchmark {
8897 reportFormat = " csv" // csv report format
8998 }
9099
91- fork {
100+ create( " fork" ) {
92101 include(" CommonBenchmark" )
93102 iterations = 5
94103 iterationTime = 300
@@ -100,18 +109,21 @@ benchmark {
100109
101110 // Setup configurations
102111 targets {
103- // This one matches target name, e.g. 'jvm', 'js',
112+ // This one matches the target name, e.g. 'jvm', 'js',
104113 // and registers its 'main' compilation, so 'jvm' registers 'jvmMain'
105114 register(" jvm" ) {
115+ this as JvmBenchmarkTarget
106116 jmhVersion = " 1.37"
107117 }
108- // This one matches source set name, e.g. 'jvmMain', 'jvmTest', etc
118+ // This one matches the source set name, e.g. 'jvmMain', 'jvmTest', etc
109119 // and register the corresponding compilation (here the 'benchmark' compilation declared in the 'jvm' target)
110120 register(" jvmBenchmark" ) {
121+ this as JvmBenchmarkTarget
111122 jmhVersion = " 1.37"
112123 }
113124 register(" jsDefaultExecutor" )
114125 register(" jsBuiltInExecutor" ) {
126+ this as JsBenchmarkTarget
115127 jsBenchmarksExecutor = JsBenchmarksExecutor .BuiltIn
116128 }
117129 register(" wasmJs" )
0 commit comments