Skip to content

Commit 435fd9b

Browse files
Abduqodiri Qurbonzodaqurbonzoda
authored andcommitted
Create a separate template project for testing separate benchmark source sets
1 parent 6321da0 commit 435fd9b

File tree

10 files changed

+74
-26
lines changed

10 files changed

+74
-26
lines changed

integration/src/main/kotlin/kotlinx/benchmark/integration/ProjectBuilder.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@ package kotlinx.benchmark.integration
22

33
class ProjectBuilder {
44
private val configurations = mutableMapOf<String, BenchmarkConfiguration>()
5-
private val targets = mutableMapOf<String, BenchmarkTarget>()
65

76
var kotlinVersion: String = System.getProperty("kotlin_version")
87
var jvmToolchain: Int = 8
98

109
fun configuration(name: String, configuration: BenchmarkConfiguration.() -> Unit = {}) {
1110
configurations[name] = BenchmarkConfiguration().apply(configuration)
1211
}
13-
fun register(name: String, configuration: BenchmarkTarget.() -> Unit = {}) {
14-
targets[name] = BenchmarkTarget().apply(configuration)
15-
}
1612

1713
fun build(original: String): String {
1814

@@ -22,9 +18,6 @@ benchmark {
2218
configurations {
2319
${configurations.flatMap { it.value.lines(it.key) }.joinToString("\n ")}
2420
}
25-
targets {
26-
${targets.flatMap { it.value.lines(it.key) }.joinToString("\n ")}
27-
}
2821
}
2922
""".trimIndent()
3023

integration/src/test/kotlin/kotlinx/benchmark/integration/SourceSetAsBenchmarkTargetTest.kt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,28 @@ class SourceSetAsBenchmarkTargetTest : GradleTest() {
77

88
@Test
99
fun testSupportForSourceSetsAsBenchmarkTargets() {
10-
val jvmBenchmark = "jvmBenchmark"
11-
val configuration = "jsonDefault"
12-
val targets = listOf("js", "wasmJs", "jvm", "native", jvmBenchmark)
10+
val targets = listOf("jvmCustom", "jsCustom")
1311

1412
val runner =
15-
project("kotlin-multiplatform", true) {
16-
configuration(configuration) {
13+
project("kotlin-multiplatform-separate-source-set", true) {
14+
configuration("csv") {
1715
iterations = 1
1816
iterationTime = 100
1917
iterationTimeUnit = "ms"
18+
reportFormat = "csv"
2019
}
21-
register(jvmBenchmark) { jmhVersion = "1.21" }
2220
}
2321

24-
runner.runAndSucceed("${configuration}Benchmark")
25-
val reports = reports(configuration)
26-
assertEquals(targets.size, reports.size)
27-
assertEquals(targets.map { "$it.json" }.toSet(), reports.map(File::getName).toSet())
22+
runner.runAndSucceed("benchmark") {
23+
assertTasksExecuted(targets.map { ":${it}Benchmark" })
24+
}
25+
val jsonReports = reports("main").map(File::getName).filter { it.endsWith(".json") }
26+
assertEquals(targets.map { "$it.json" }.toSet(), jsonReports.toSet())
27+
28+
runner.runAndSucceed("csvBenchmark") {
29+
assertTasksExecuted(targets.map { ":${it}CsvBenchmark" })
30+
}
31+
val csvReports = reports("csv").map(File::getName).filter { it.endsWith(".csv") }
32+
assertEquals(targets.map { "$it.csv" }.toSet(), csvReports.toSet())
2833
}
2934
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
kotlin {
2+
jvm {
3+
compilations.create('custom') { associateWith(compilations.main) }
4+
}
5+
js {
6+
nodejs()
7+
compilations.create('custom') { associateWith(compilations.main) }
8+
}
9+
}
10+
11+
benchmark {
12+
targets {
13+
register("jvmCustom")
14+
register("jsCustom")
15+
}
16+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.gradle.jvmargs=-Xmx2g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package test
2+
3+
data class CommonTestData(var value: Double)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package test
2+
3+
import kotlinx.benchmark.*
4+
import kotlin.math.*
5+
6+
@State(Scope.Benchmark)
7+
@Warmup(iterations = 2, time = 100, timeUnit = BenchmarkTimeUnit.MILLISECONDS)
8+
@Measurement(iterations = 3, time = 200, timeUnit = BenchmarkTimeUnit.MILLISECONDS)
9+
@OutputTimeUnit(BenchmarkTimeUnit.MILLISECONDS)
10+
open class JsCustomBenchmark {
11+
@Benchmark
12+
open fun hashCodeBenchmark(): Int {
13+
val value = log(sqrt(3.0) * cos(3.0), 2.0)
14+
return JsTestData(CommonTestData(value)).hashCode()
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package test
2+
3+
data class JsTestData(var value: CommonTestData)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package test
2+
3+
import kotlinx.benchmark.*
4+
import kotlin.math.*
5+
6+
@State(Scope.Benchmark)
7+
@Warmup(iterations = 2, time = 100, timeUnit = BenchmarkTimeUnit.MILLISECONDS)
8+
@Measurement(iterations = 3, time = 200, timeUnit = BenchmarkTimeUnit.MILLISECONDS)
9+
@OutputTimeUnit(BenchmarkTimeUnit.MILLISECONDS)
10+
open class JvmCustomBenchmark {
11+
@Benchmark
12+
open fun hashCodeBenchmark(): Int {
13+
val value = log(sqrt(3.0) * cos(3.0), 2.0)
14+
return JvmTestData(CommonTestData(value)).hashCode()
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package test
2+
3+
data class JvmTestData(var value: CommonTestData)

integration/src/test/resources/templates/kotlin-multiplatform/build.gradle

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,14 @@ import org.jetbrains.kotlin.konan.target.KonanTarget
22
import org.jetbrains.kotlin.konan.target.HostManager
33

44
kotlin {
5-
jvm {
6-
compilations.create('benchmark') { associateWith(compilations.main) }
7-
}
5+
jvm {}
86
js { nodejs() }
97
wasmJs { d8() }
108

119
if (HostManager.hostIsLinux) linuxX64('native')
1210
if (HostManager.hostIsMingw) mingwX64('native')
1311
if (HostManager.host == KonanTarget.MACOS_X64.INSTANCE) macosX64('native')
1412
if (HostManager.host == KonanTarget.MACOS_ARM64.INSTANCE) macosArm64('native')
15-
16-
sourceSets {
17-
jvmBenchmark {
18-
dependsOn(jvmMain)
19-
}
20-
}
2113
}
2214

2315
benchmark {

0 commit comments

Comments
 (0)