Skip to content

Instantly share code, notes, and snippets.

@qwwdfsad
Created May 16, 2022 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qwwdfsad/fb646efd7a52b3a18bf0536ba37341bb to your computer and use it in GitHub Desktop.
Save qwwdfsad/fb646efd7a52b3a18bf0536ba37341bb to your computer and use it in GitHub Desktop.
@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)
}
}
}
}
@qwwdfsad
Copy link
Author

Benchmark                 Mode  Cnt   Score   Error  Units
PushVsPullBenchmark.pull  avgt   10   2.295 ± 0.315  ms/op
PushVsPullBenchmark.push  avgt   10  67.274 ± 3.652  ms/op

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment