Skip to content

Commit d3f1f23

Browse files
authored
Multiplatform benchmarks baseline (#4350)
Update kotlinx-benchmark-based setup in kotlinx-coroutines-core and add a basic zero-contention benchmark for locks
1 parent 3ed623a commit d3f1f23

File tree

13 files changed

+103
-28
lines changed

13 files changed

+103
-28
lines changed

buildSrc/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ dependencies {
6363
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk7")
6464
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib")
6565
}
66-
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-plugin:0.4.9")
66+
implementation("org.jetbrains.kotlinx:kotlinx-benchmark-plugin:${version("benchmarks")}")
6767
implementation("org.jetbrains.kotlinx:kotlinx-knit:${version("knit")}")
6868
implementation("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${version("atomicfu")}")
6969
}

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ group=org.jetbrains.kotlinx
44
kotlin_version=2.1.0
55
# DO NOT rename this property without adapting kotlinx.train build chain:
66
atomicfu_version=0.26.1
7+
benchmarks_version=0.4.13
8+
benchmarks_jmh_version=1.37
79

810
# Dependencies
911
junit_version=4.12
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## kotlinx-coroutines-core benchmarks
2+
3+
Multiplatform benchmarks for kotlinx-coroutines-core.
4+
5+
This source-set contains benchmarks that leverage `internal` API (e.g. `suspendCancellableCoroutineReusable`) or
6+
that are multiplatform (-> only supported with `kotlinx-benchmarks` which is less convenient than `jmh` plugin).
7+
For JVM-only non-internal benchmarks, consider using `benchmarks` top-level project.
8+
9+
### Usage
10+
11+
```
12+
// JVM only
13+
./gradlew :kotlinx-coroutines-core:jvmBenchmarkBenchmarkJar
14+
java -jar kotlinx-coroutines-core/build/benchmarks/jvmBenchmark/jars/kotlinx-coroutines-core-jvmBenchmark-jmh-*-JMH.jar
15+
16+
// Native, OS X
17+
./gradlew :kotlinx-coroutines-core:macosArm64BenchmarkBenchmark
18+
19+
// Figure out what to use
20+
./gradlew :kotlinx-coroutines-core:tasks | grep -i bench
21+
```

kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/SemaphoreBenchmark.kt renamed to kotlinx-coroutines-core/benchmarks/jvm/kotlin/kotlinx/coroutines/SemaphoreBenchmark.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ open class SemaphoreBenchmark {
7676

7777
enum class SemaphoreBenchDispatcherCreator(val create: (parallelism: Int) -> CoroutineDispatcher) {
7878
FORK_JOIN({ parallelism -> ForkJoinPool(parallelism).asCoroutineDispatcher() }),
79-
DEFAULT({ parallelism -> ExperimentalCoroutineDispatcher(corePoolSize = parallelism, maxPoolSize = parallelism) })
79+
DEFAULT({ parallelism -> CoroutineScheduler(corePoolSize = parallelism, maxPoolSize = parallelism).asCoroutineDispatcher() })
8080
}
8181

8282
private const val WORK_INSIDE = 50
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ open class ChannelProducerConsumerBenchmark {
133133

134134
enum class DispatcherCreator(val create: (parallelism: Int) -> CoroutineDispatcher) {
135135
FORK_JOIN({ parallelism -> ForkJoinPool(parallelism).asCoroutineDispatcher() }),
136-
DEFAULT({ parallelism -> ExperimentalCoroutineDispatcher(corePoolSize = parallelism, maxPoolSize = parallelism) })
136+
DEFAULT({ parallelism -> CoroutineScheduler(corePoolSize = parallelism, maxPoolSize = parallelism).asCoroutineDispatcher() })
137137
}
138138

139139
enum class ChannelCreator(private val capacity: Int) {

0 commit comments

Comments
 (0)