Skip to content

Commit 12bd94a

Browse files
committed
Fixed according to the code review
1 parent 78b8868 commit 12bd94a

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

benchmarks/src/jmh/kotlin/benchmarks/flow/FlattenMergeBenchmark.kt

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package benchmarks.flow
22

33
import kotlinx.coroutines.*
4-
import kotlinx.coroutines.channels.consumesAll
54
import kotlinx.coroutines.flow.*
65
import org.openjdk.jmh.annotations.*
7-
import org.openjdk.jmh.infra.Blackhole
86
import java.util.concurrent.TimeUnit
7+
import kotlin.math.ceil
98

109
/**
1110
* This benchmark can be considered as a macro benchmark for the [kotlinx.coroutines.sync.Semaphore]
@@ -18,6 +17,10 @@ import java.util.concurrent.TimeUnit
1817
@Fork(1)
1918
open class FlattenMergeBenchmark {
2019

20+
/**
21+
* Number of flows that are merged in this benchmark. Negative number means that number of flows
22+
* will be computed as -([flows] * [concurrency]), positive number will be chosen as number of flows.
23+
*/
2124
@Param("-10", "-1", "100", "500")
2225
private var flows: Int = 0
2326

@@ -30,16 +33,16 @@ open class FlattenMergeBenchmark {
3033

3134
@Setup
3235
fun setup() {
33-
val flowsCount = if (flows < 0) {
36+
val flowsNumber = if (flows < 0) {
3437
-flows * concurrency
3538
}
3639
else {
3740
flows
3841
}
3942

40-
flow = (1..flowsCount).asFlow().map {
43+
flow = (1..flowsNumber).asFlow().map {
4144
flow {
42-
repeat(ELEMENTS / flowsCount) {
45+
repeat(ceil(ELEMENTS / flowsNumber.toDouble()).toInt()) {
4346
emit(it)
4447
}
4548
}
@@ -52,4 +55,4 @@ open class FlattenMergeBenchmark {
5255
}
5356
}
5457

55-
private const val ELEMENTS = 100
58+
private const val ELEMENTS = 10_000

0 commit comments

Comments
 (0)