Skip to content

Commit 2d89b8c

Browse files
committed
change benchmarks
1 parent a1824e9 commit 2d89b8c

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

benchmarks/src/jmh/kotlin/benchmarks/ChannelSinkBenchmark.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import kotlin.coroutines.*
1313
@State(Scope.Benchmark)
1414
@Fork(1)
1515
open class ChannelSinkBenchmark {
16+
@Param("${Channel.RENDEZVOUS}", "${Channel.BUFFERED}")
17+
var capacity: Int = 0
18+
1619
private val tl = ThreadLocal.withInitial({ 42 })
1720
private val tl2 = ThreadLocal.withInitial({ 239 })
1821

@@ -42,15 +45,15 @@ open class ChannelSinkBenchmark {
4245
.fold(0) { a, b -> a + b }
4346
}
4447

45-
private fun Channel.Factory.range(start: Int, count: Int, context: CoroutineContext) = GlobalScope.produce(context) {
48+
private fun Channel.Factory.range(start: Int, count: Int, context: CoroutineContext) = GlobalScope.produce(context, capacity) {
4649
for (i in start until (start + count))
4750
send(i)
4851
}
4952

5053
// Migrated from deprecated operators, are good only for stressing channels
5154

5255
private fun <E> ReceiveChannel<E>.filter(context: CoroutineContext = Dispatchers.Unconfined, predicate: suspend (E) -> Boolean): ReceiveChannel<E> =
53-
GlobalScope.produce(context, onCompletion = { cancel() }) {
56+
GlobalScope.produce(context, capacity, onCompletion = { cancel() }) {
5457
for (e in this@filter) {
5558
if (predicate(e)) send(e)
5659
}

benchmarks/src/jmh/kotlin/benchmarks/ChannelSinkDepthBenchmark.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import kotlin.coroutines.*
1313
@State(Scope.Benchmark)
1414
@Fork(2)
1515
open class ChannelSinkDepthBenchmark {
16+
@Param("${Channel.RENDEZVOUS}", "${Channel.BUFFERED}")
17+
var capacity: Int = 0
18+
1619
private val tl = ThreadLocal.withInitial({ 42 })
1720

1821
private val unconfinedOneElement = Dispatchers.Unconfined + tl.asContextElement()
@@ -45,7 +48,7 @@ open class ChannelSinkDepthBenchmark {
4548
}
4649

4750
private fun Channel.Factory.range(start: Int, count: Int, context: CoroutineContext) =
48-
GlobalScope.produce(context) {
51+
GlobalScope.produce(context, capacity) {
4952
for (i in start until (start + count))
5053
send(i)
5154
}
@@ -57,7 +60,7 @@ open class ChannelSinkDepthBenchmark {
5760
context: CoroutineContext = Dispatchers.Unconfined,
5861
predicate: suspend (Int) -> Boolean
5962
): ReceiveChannel<Int> =
60-
GlobalScope.produce(context, onCompletion = { cancel() }) {
63+
GlobalScope.produce(context, capacity, onCompletion = { cancel() }) {
6164
deeplyNestedFilter(this, callTraceDepth, predicate)
6265
}
6366

benchmarks/src/jmh/kotlin/benchmarks/ChannelSinkNoAllocationsBenchmark.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import kotlin.coroutines.*
1313
@State(Scope.Benchmark)
1414
@Fork(1)
1515
open class ChannelSinkNoAllocationsBenchmark {
16+
@Param("${Channel.RENDEZVOUS}", "${Channel.BUFFERED}")
17+
var capacity: Int = 0
18+
1619
private val unconfined = Dispatchers.Unconfined
1720

1821
@Benchmark
@@ -26,7 +29,7 @@ open class ChannelSinkNoAllocationsBenchmark {
2629
return size
2730
}
2831

29-
private fun Channel.Factory.range(context: CoroutineContext) = GlobalScope.produce(context) {
32+
private fun Channel.Factory.range(context: CoroutineContext) = GlobalScope.produce(context, capacity) {
3033
for (i in 0 until 100_000)
3134
send(Unit) // no allocations
3235
}

0 commit comments

Comments
 (0)