Skip to content

Commit a87ee33

Browse files
committed
migrate examples to kotlin dsl
1 parent b6d59df commit a87ee33

File tree

9 files changed

+40
-108
lines changed

9 files changed

+40
-108
lines changed

examples/build.gradle renamed to examples/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ subprojects {
55
repositories {
66
mavenCentral()
77
}
8-
}
8+
}

examples/java/build.gradle renamed to examples/java/build.gradle.kts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1+
import kotlinx.benchmark.gradle.*
2+
13
buildscript {
24
dependencies {
3-
classpath "org.jetbrains.kotlinx:kotlinx-benchmark-plugin"
5+
classpath("org.jetbrains.kotlinx:kotlinx-benchmark-plugin")
46
}
57
}
68

79
plugins {
8-
id "java"
10+
java
11+
id("org.jetbrains.kotlinx.benchmark")
912
}
1013

11-
apply plugin: "org.jetbrains.kotlinx.benchmark"
12-
1314
dependencies {
1415
implementation(project(":kotlinx-benchmark-runtime"))
1516
}
1617

1718
benchmark {
1819
configurations {
19-
main {
20+
named("main") {
2021
iterationTime = 300
2122
iterationTimeUnit = "ms"
2223
}
23-
singleParam {
24+
create("singleParam") {
2425
iterationTime = 300
2526
iterationTimeUnit = "ms"
2627
param("stringValue", "C", "D")
@@ -29,6 +30,7 @@ benchmark {
2930
}
3031
targets {
3132
register("main") {
33+
this as JvmBenchmarkTarget
3234
jmhVersion = "1.21"
3335
}
3436
}

examples/kotlin-multiplatform/build.gradle renamed to examples/kotlin-multiplatform/build.gradle.kts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import kotlinx.benchmark.gradle.*
12
import org.jetbrains.kotlin.konan.target.HostManager
23
import org.jetbrains.kotlin.konan.target.KonanTarget
34
import kotlinx.benchmark.gradle.JsBenchmarksExecutor
45

56
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")
910
}
1011

1112
// how to apply plugin to a specific source set?
@@ -15,13 +16,13 @@ allOpen {
1516

1617
kotlin {
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
5764
benchmark {
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")

examples/kotlin/benchmarks/src/TestBenchmark.kt

Lines changed: 0 additions & 28 deletions
This file was deleted.

examples/kotlin/build.gradle

Lines changed: 0 additions & 49 deletions
This file was deleted.

examples/kotlin/main/src/TestData.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

plugin/settings.gradle renamed to plugin/settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ pluginManagement {
33
gradlePluginPortal()
44
}
55
}
6-
rootProject.name = 'kotlinx-benchmark-plugin'
6+
rootProject.name = "kotlinx-benchmark-plugin"

0 commit comments

Comments
 (0)