Skip to content

Commit a1824e9

Browse files
committed
add threads annotation
1 parent a210607 commit a1824e9

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

benchmarks/src/jmh/kotlin/benchmarks/BufferedChannelBenchmark.kt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ import kotlin.coroutines.*
1111
@BenchmarkMode(Mode.Throughput, Mode.AverageTime)
1212
@OutputTimeUnit(TimeUnit.MICROSECONDS)
1313
@State(Scope.Benchmark)
14+
@Threads(3)
1415
@Fork(1)
1516
open class BufferedChannelBenchmark {
1617
@Param("1", "2")
1718
var capacity: Int = 0
1819

1920
@Benchmark
2021
fun channelPipeline(): Int = runBlocking {
21-
run(Dispatchers.IO.limitedParallelism(3))
22+
run(Dispatchers.Unconfined)
2223
}
2324

24-
private suspend inline fun run(context: CoroutineContext): Int =
25-
Channel.range(100_000, context)
26-
.filter(context) { it % 4 == 0 }
25+
private suspend inline fun run(context: CoroutineContext) =
26+
Channel
27+
.range(100_000, context)
2728
.fold(0) { a, b -> a + b }
2829

2930
private fun Channel.Factory.range(count: Int, context: CoroutineContext) = GlobalScope.produce(context, capacity) {
@@ -33,13 +34,6 @@ open class BufferedChannelBenchmark {
3334

3435
// Migrated from deprecated operators, are good only for stressing channels
3536

36-
private fun ReceiveChannel<Int>.filter(context: CoroutineContext = Dispatchers.Unconfined, predicate: suspend (Int) -> Boolean): ReceiveChannel<Int> =
37-
GlobalScope.produce(context, onCompletion = { cancel() }) {
38-
for (e in this@filter) {
39-
if (predicate(e)) send(e)
40-
}
41-
}
42-
4337
private suspend inline fun <E, R> ReceiveChannel<E>.fold(initial: R, operation: (acc: R, E) -> R): R {
4438
var accumulator = initial
4539
consumeEach {

0 commit comments

Comments
 (0)