1
+ import kotlinx.benchmark.gradle.*
1
2
import org.jetbrains.kotlin.konan.target.HostManager
2
3
import org.jetbrains.kotlin.konan.target.KonanTarget
3
4
import kotlinx.benchmark.gradle.JsBenchmarksExecutor
4
5
5
6
plugins {
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" )
9
10
}
10
11
11
12
// how to apply plugin to a specific source set?
@@ -15,13 +16,13 @@ allOpen {
15
16
16
17
kotlin {
17
18
jvm {
18
- compilations. create(" benchmark" ) { associateWith(compilations. main) }
19
+ compilations.create(" benchmark" ) { associateWith(compilations.getByName( " main" ) ) }
19
20
}
20
21
js(" jsIr" , IR ) { nodejs() }
21
22
js(" jsIrBuiltIn" , IR ) { nodejs() }
22
23
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" )
25
26
if (HostManager .hostIsLinux) linuxX64(" native" )
26
27
if (HostManager .hostIsMingw) mingwX64(" native" )
27
28
@@ -32,39 +33,45 @@ kotlin {
32
33
}
33
34
34
35
sourceSets {
35
- commonMain {
36
+ getByName( " commonMain" ) {
36
37
dependencies {
37
- implementation project(" :kotlinx-benchmark-runtime" )
38
+ implementation( project(" :kotlinx-benchmark-runtime" ) )
38
39
}
39
40
}
40
41
41
- jvmMain {}
42
+ getByName( " jvmMain" ) {}
42
43
43
- wasmJsMain {}
44
+ getByName( " wasmJsMain" ) {}
44
45
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)
48
55
}
49
56
50
- nativeMain {
51
- dependsOn(commonMain)
57
+ getByName( " nativeMain" ) {
58
+ dependsOn(getByName( " commonMain" ) )
52
59
}
53
60
}
54
61
}
55
62
56
63
// Configure benchmark
57
64
benchmark {
58
65
configurations {
59
- main { // --> jvmBenchmark, jsBenchmark, < native target> Benchmark , benchmark
66
+ named( " main" ) { // --> jvmBenchmark, jsBenchmark, <native target>Benchmark, benchmark
60
67
iterations = 5 // number of iterations
61
68
iterationTime = 300
62
69
iterationTimeUnit = " ms"
63
70
advanced(" jvmForks" , 3 )
64
71
advanced(" jsUseBridge" , true )
65
72
}
66
73
67
- params {
74
+ create( " params" ) {
68
75
iterations = 5 // number of iterations
69
76
iterationTime = 300
70
77
iterationTimeUnit = " ms"
@@ -73,7 +80,7 @@ benchmark {
73
80
param(" unused" , 6 , 9 )
74
81
}
75
82
76
- fast { // --> jvmFastBenchmark, jsFastBenchmark, < native target> FastBenchmark , fastBenchmark
83
+ create( " fast" ) { // --> jvmFastBenchmark, jsFastBenchmark, <native target>FastBenchmark, fastBenchmark
77
84
include(" Common" )
78
85
exclude(" long" )
79
86
iterations = 5
@@ -82,7 +89,7 @@ benchmark {
82
89
advanced(" nativeGCAfterIteration" , true )
83
90
}
84
91
85
- csv {
92
+ create( " csv" ) {
86
93
include(" Common" )
87
94
exclude(" long" )
88
95
iterations = 1
@@ -91,7 +98,7 @@ benchmark {
91
98
reportFormat = " csv" // csv report format
92
99
}
93
100
94
- fork {
101
+ create( " fork" ) {
95
102
include(" CommonBenchmark" )
96
103
iterations = 5
97
104
iterationTime = 300
@@ -106,15 +113,18 @@ benchmark {
106
113
// This one matches target name, e.g. 'jvm', 'js',
107
114
// and registers its 'main' compilation, so 'jvm' registers 'jvmMain'
108
115
register(" jvm" ) {
116
+ this as JvmBenchmarkTarget
109
117
jmhVersion = " 1.21"
110
118
}
111
119
// This one matches source set name, e.g. 'jvmMain', 'jvmTest', etc
112
120
// and register the corresponding compilation (here the 'benchmark' compilation declared in the 'jvm' target)
113
121
register(" jvmBenchmark" ) {
122
+ this as JvmBenchmarkTarget
114
123
jmhVersion = " 1.21"
115
124
}
116
125
register(" jsIr" )
117
126
register(" jsIrBuiltIn" ) {
127
+ this as JsBenchmarkTarget
118
128
jsBenchmarksExecutor = JsBenchmarksExecutor .BuiltIn
119
129
}
120
130
register(" wasmJs" )
0 commit comments