1+ import kotlinx.benchmark.gradle.*
12import org.jetbrains.kotlin.konan.target.HostManager
23import org.jetbrains.kotlin.konan.target.KonanTarget
34import kotlinx.benchmark.gradle.JsBenchmarksExecutor
45
56plugins {
6- id " org.jetbrains. kotlin. multiplatform"
7- id " org.jetbrains. kotlin. plugin.allopen" version " 1.8.21"
8- id " org.jetbrains.kotlinx.benchmark"
7+ kotlin( " multiplatform" )
8+ kotlin( " plugin.allopen" ) version " 1.8.21"
9+ id( " org.jetbrains.kotlinx.benchmark" )
910}
1011
1112// how to apply plugin to a specific source set?
@@ -15,13 +16,13 @@ allOpen {
1516
1617kotlin {
1718 jvm {
18- compilations. create(" benchmark" ) { associateWith(compilations. main) }
19+ compilations.create(" benchmark" ) { associateWith(compilations.getByName( " main" ) ) }
1920 }
2021 js(" jsIr" , IR ) { nodejs() }
2122 js(" jsIrBuiltIn" , IR ) { nodejs() }
2223 wasm(" wasmJs" ) { d8() }
23- if (HostManager . host == KonanTarget . MACOS_X64 . INSTANCE ) macosX64(" native" )
24- if (HostManager . host == KonanTarget . MACOS_ARM64 . INSTANCE ) macosArm64(" native" )
24+ if (HostManager .host == KonanTarget .MACOS_X64 ) macosX64(" native" )
25+ if (HostManager .host == KonanTarget .MACOS_ARM64 ) macosArm64(" native" )
2526 if (HostManager .hostIsLinux) linuxX64(" native" )
2627 if (HostManager .hostIsMingw) mingwX64(" native" )
2728
@@ -32,39 +33,45 @@ kotlin {
3233 }
3334
3435 sourceSets {
35- commonMain {
36+ getByName( " commonMain" ) {
3637 dependencies {
37- implementation project(" :kotlinx-benchmark-runtime" )
38+ implementation( project(" :kotlinx-benchmark-runtime" ) )
3839 }
3940 }
4041
41- jvmMain {}
42+ getByName( " jvmMain" ) {}
4243
43- wasmJsMain {}
44+ getByName( " wasmJsMain" ) {}
4445
45- jsMain {
46- jsIrMain. dependsOn(it)
47- jsIrBuiltInMain. dependsOn(it)
46+
47+ val jsMain by creating
48+
49+ getByName(" jsIrMain" ) {
50+ dependsOn(jsMain)
51+ }
52+
53+ getByName(" jsIrBuiltInMain" ) {
54+ dependsOn(jsMain)
4855 }
4956
50- nativeMain {
51- dependsOn(commonMain)
57+ getByName( " nativeMain" ) {
58+ dependsOn(getByName( " commonMain" ) )
5259 }
5360 }
5461}
5562
5663// Configure benchmark
5764benchmark {
5865 configurations {
59- main { // --> jvmBenchmark, jsBenchmark, < native target> Benchmark , benchmark
66+ named( " main" ) { // --> jvmBenchmark, jsBenchmark, <native target>Benchmark, benchmark
6067 iterations = 5 // number of iterations
6168 iterationTime = 300
6269 iterationTimeUnit = " ms"
6370 advanced(" jvmForks" , 3 )
6471 advanced(" jsUseBridge" , true )
6572 }
6673
67- params {
74+ create( " params" ) {
6875 iterations = 5 // number of iterations
6976 iterationTime = 300
7077 iterationTimeUnit = " ms"
@@ -73,7 +80,7 @@ benchmark {
7380 param(" unused" , 6 , 9 )
7481 }
7582
76- fast { // --> jvmFastBenchmark, jsFastBenchmark, < native target> FastBenchmark , fastBenchmark
83+ create( " fast" ) { // --> jvmFastBenchmark, jsFastBenchmark, <native target>FastBenchmark, fastBenchmark
7784 include(" Common" )
7885 exclude(" long" )
7986 iterations = 5
@@ -82,7 +89,7 @@ benchmark {
8289 advanced(" nativeGCAfterIteration" , true )
8390 }
8491
85- csv {
92+ create( " csv" ) {
8693 include(" Common" )
8794 exclude(" long" )
8895 iterations = 1
@@ -91,7 +98,7 @@ benchmark {
9198 reportFormat = " csv" // csv report format
9299 }
93100
94- fork {
101+ create( " fork" ) {
95102 include(" CommonBenchmark" )
96103 iterations = 5
97104 iterationTime = 300
@@ -106,15 +113,18 @@ benchmark {
106113 // This one matches target name, e.g. 'jvm', 'js',
107114 // and registers its 'main' compilation, so 'jvm' registers 'jvmMain'
108115 register(" jvm" ) {
116+ this as JvmBenchmarkTarget
109117 jmhVersion = " 1.21"
110118 }
111119 // This one matches source set name, e.g. 'jvmMain', 'jvmTest', etc
112120 // and register the corresponding compilation (here the 'benchmark' compilation declared in the 'jvm' target)
113121 register(" jvmBenchmark" ) {
122+ this as JvmBenchmarkTarget
114123 jmhVersion = " 1.21"
115124 }
116125 register(" jsIr" )
117126 register(" jsIrBuiltIn" ) {
127+ this as JsBenchmarkTarget
118128 jsBenchmarksExecutor = JsBenchmarksExecutor .BuiltIn
119129 }
120130 register(" wasmJs" )
0 commit comments