Created
May 16, 2022 08:23
-
-
Save qwwdfsad/fb646efd7a52b3a18bf0536ba37341bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Warmup(iterations = 7, time = 1) | |
@Measurement(iterations = 5, time = 1) | |
@BenchmarkMode(Mode.AverageTime) | |
@OutputTimeUnit(TimeUnit.MILLISECONDS) | |
@State(Scope.Benchmark) | |
@Fork(2) | |
open class PushVsPullBenchmark { | |
private val source = flow { | |
repeat(100_000) { emit(it) } | |
} | |
@Benchmark | |
fun pull() = runBlocking { | |
source.onEach { require(it >= 0) }.collect() | |
} | |
@Benchmark | |
fun push() = runBlocking { | |
source.iterate { | |
while (hasNext()) { | |
require(next() >= 0) | |
} | |
} | |
} | |
} |
Author
qwwdfsad
commented
May 16, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment