kotlinx-benchmark icon indicating copy to clipboard operation
kotlinx-benchmark copied to clipboard

Support usages of Blackhole outside of the @Benchmark methods

Open qwwdfsad opened this issue 1 year ago • 0 comments
trafficstars

Real-world use-case: https://github.com/sellmair/evas/blob/sellmair/evas/src/commonBenchmark/kotlin/io/sellmair/evas/benchmark/events/EmitBenchmark.kt

The scenario is the following: @Setup sets up the target entity/system and sets up a data egress that is repeatedly invoked from the target benchmark method. For the benchmark to be representative, egress should properly consume the data.

The boiled down example might be the following:

lateinit var flow: Flow<Int>

@Setup 
fun prepare(bh: Blackhole) {
    flow = createFlow().onEach { bh.consume(it) }
}

@Benchmark
fun collect() {
    // Measure collect only and the cost of the data flow
    flow.collect()
}

qwwdfsad avatar Aug 23 '24 15:08 qwwdfsad