File tree Expand file tree Collapse file tree 9 files changed +61
-25
lines changed
kotlin/kotlinx/coroutines Expand file tree Collapse file tree 9 files changed +61
-25
lines changed Original file line number Diff line number Diff line change 2
2
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
3
*/
4
4
5
+ plugins {
6
+ id ' org.jetbrains.kotlinx.benchmark' version ' 0.4.9'
7
+ }
8
+
5
9
apply plugin : ' org.jetbrains.kotlin.multiplatform'
6
10
apply plugin : ' org.jetbrains.dokka'
7
11
@@ -167,6 +171,13 @@ kotlin {
167
171
168
172
// For animal sniffer
169
173
withJava()
174
+ compilations. create(' benchmark' ) { associateWith(compilations. main) }
175
+ }
176
+ }
177
+
178
+ benchmark {
179
+ targets {
180
+ register(" jvmBenchmark" )
170
181
}
171
182
}
172
183
Original file line number Diff line number Diff line change
1
+ ## kotlinx-coroutines-core benchmarks
2
+
3
+ This source-set contains benchmarks that leverage ` internal ` API (e.g. ` suspendCancellableCoroutineReusable ` )
4
+ and thus cannot be written in ` benchmarks ` module.
5
+
6
+ This is an interim solution unless we introduce clear separation of responsibilities in benchmark modules
7
+ and decide on their usability.
8
+
9
+
10
+ ### Usage
11
+
12
+ ```
13
+ ./gradlew :kotlinx-coroutines-core:jvmBenchmarkBenchmarkJar
14
+ java -jar kotlinx-coroutines-core/build/benchmarks/jvmBenchmark/jars/kotlinx-coroutines-core-jvmBenchmark-jmh-1.7.2-SNAPSHOT-JMH.jar
15
+ ```
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
+ */
4
+
5
+ package kotlinx.coroutines
6
+
7
+ import java.util.concurrent.*
8
+
9
+ public fun doGeomDistrWork (work : Int ) {
10
+ // We use geometric distribution here. We also checked on macbook pro 13" (2017) that the resulting work times
11
+ // are distributed geometrically, see https://github.com/Kotlin/kotlinx.coroutines/pull/1464#discussion_r355705325
12
+ val p = 1.0 / work
13
+ val r = ThreadLocalRandom .current()
14
+ while (true ) {
15
+ if (r.nextDouble() < p) break
16
+ }
17
+ }
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2
+ * Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
3
*/
4
4
5
- package benchmarks
5
+ package kotlinx.coroutines
6
6
7
- import benchmarks.common.*
8
7
import kotlinx.coroutines.*
9
8
import kotlinx.coroutines.channels.*
10
9
import kotlinx.coroutines.scheduling.*
@@ -80,8 +79,7 @@ open class SemaphoreBenchmark {
80
79
}
81
80
82
81
enum class SemaphoreBenchDispatcherCreator (val create : (parallelism: Int ) -> CoroutineDispatcher ) {
83
- // FORK_JOIN({ parallelism -> ForkJoinPool(parallelism).asCoroutineDispatcher() }),
84
- @Suppress(" INVISIBLE_MEMBER" , " INVISIBLE_REFERENCE" )
82
+ FORK_JOIN ({ parallelism -> ForkJoinPool (parallelism).asCoroutineDispatcher() }),
85
83
DEFAULT ({ parallelism -> ExperimentalCoroutineDispatcher (corePoolSize = parallelism, maxPoolSize = parallelism) })
86
84
}
87
85
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2
+ * Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
3
*/
4
4
5
- package benchmarks
5
+ package kotlinx.coroutines.channels
6
6
7
- import benchmarks.common.*
8
7
import kotlinx.coroutines.*
9
8
import kotlinx.coroutines.channels.Channel
10
9
import kotlinx.coroutines.scheduling.*
11
10
import kotlinx.coroutines.selects.select
12
11
import org.openjdk.jmh.annotations.*
13
12
import java.lang.Integer.max
13
+ import java.util.concurrent.ForkJoinPool
14
14
import java.util.concurrent.Phaser
15
15
import java.util.concurrent.TimeUnit
16
16
@@ -136,8 +136,7 @@ open class ChannelProducerConsumerBenchmark {
136
136
}
137
137
138
138
enum class DispatcherCreator (val create : (parallelism: Int ) -> CoroutineDispatcher ) {
139
- // FORK_JOIN({ parallelism -> ForkJoinPool(parallelism).asCoroutineDispatcher() }),
140
- @Suppress(" INVISIBLE_MEMBER" , " INVISIBLE_REFERENCE" )
139
+ FORK_JOIN ({ parallelism -> ForkJoinPool (parallelism).asCoroutineDispatcher() }),
141
140
DEFAULT ({ parallelism -> ExperimentalCoroutineDispatcher (corePoolSize = parallelism, maxPoolSize = parallelism) })
142
141
}
143
142
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2022 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2
+ * Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
3
*/
4
4
5
- package benchmarks.tailcall
5
+ package kotlinx.coroutines.channels
6
6
7
7
import kotlinx.coroutines.*
8
8
import kotlinx.coroutines.channels.*
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2
+ * Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
3
*/
4
4
5
- package benchmarks.tailcall
5
+ package kotlinx.coroutines.channels
6
6
7
7
import kotlinx.coroutines.*
8
8
import kotlin.coroutines.*
9
9
import kotlin.coroutines.intrinsics.*
10
10
11
- @Suppress(" INVISIBLE_MEMBER" , " INVISIBLE_REFERENCE" )
12
11
public abstract class SimpleChannel {
13
12
companion object {
14
13
const val NULL_SURROGATE : Int = - 1
@@ -83,13 +82,11 @@ class CancellableChannel : SimpleChannel() {
83
82
}
84
83
85
84
class CancellableReusableChannel : SimpleChannel () {
86
- @Suppress(" INVISIBLE_MEMBER" )
87
85
override suspend fun suspendReceive (): Int = suspendCancellableCoroutineReusable {
88
86
consumer = it.intercepted()
89
87
COROUTINE_SUSPENDED
90
88
}
91
89
92
- @Suppress(" INVISIBLE_MEMBER" )
93
90
override suspend fun suspendSend (element : Int ) = suspendCancellableCoroutineReusable<Unit > {
94
91
enqueuedValue = element
95
92
producer = it.intercepted()
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2
+ * Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
3
*/
4
4
5
- package benchmarks.tailcall
5
+ package kotlinx.coroutines.channels
6
6
7
7
import kotlinx.coroutines.*
8
8
import org.openjdk.jmh.annotations.*
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2
+ * Copyright 2016-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
3
*/
4
4
5
- @file:Suppress(" INVISIBLE_REFERENCE" , " INVISIBLE_MEMBER" )
6
-
7
- package benchmarks.flow
5
+ package kotlinx.coroutines.flow
8
6
9
7
import kotlinx.coroutines.*
10
- import kotlinx.coroutines.flow.*
11
8
import kotlinx.coroutines.flow.internal.*
9
+ import kotlinx.coroutines.flow.internal.AbortFlowException
10
+ import kotlinx.coroutines.flow.internal.unsafeFlow
12
11
import org.openjdk.jmh.annotations.*
13
- import java.util.concurrent.TimeUnit
12
+ import java.util.concurrent.*
14
13
15
14
@Warmup(iterations = 5 , time = 1 , timeUnit = TimeUnit .SECONDS )
16
15
@Measurement(iterations = 5 , time = 1 , timeUnit = TimeUnit .SECONDS )
You can’t perform that action at this time.
0 commit comments