Skip to content

Commit

Permalink
add start/stop benchmarks for fmvi and fluxo
Browse files Browse the repository at this point in the history
  • Loading branch information
Nek-12 committed Nov 29, 2024
1 parent c5d5abc commit 8d6c5d9
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 17 deletions.
5 changes: 3 additions & 2 deletions benchmarks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ benchmark {
warmups = 10
iterationTime = 100
iterationTimeUnit = "ms"
outputTimeUnit = "us"
mode = "avgt"
outputTimeUnit = "ms"
mode = "thrpt" // "thrpt" - throughput, "avgt" - average
reportFormat = "text"
// advanced("nativeGCAfterIteration", true)
// advanced("jvmForks", "definedByJmh")
}
}
targets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import org.openjdk.jmh.annotations.Setup
import org.openjdk.jmh.annotations.State
import pro.respawn.flowmvi.benchmarks.BenchmarkDefaults
import pro.respawn.flowmvi.benchmarks.setup.BenchmarkIntent
import pro.respawn.flowmvi.benchmarks.setup.optimized.optimizedStore

@Suppress("unused")
@State(Scope.Benchmark)
internal class ChannelBasedMVIBenchmark {
internal class ChannelTraditionalMVIBenchmark {

lateinit var store: ChannelBasedTraditionalStore
lateinit var scope: CoroutineScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.Setup
import org.openjdk.jmh.annotations.State
import pro.respawn.flowmvi.api.Store
import org.openjdk.jmh.annotations.Threads
import pro.respawn.flowmvi.benchmarks.BenchmarkDefaults
import pro.respawn.flowmvi.benchmarks.setup.BenchmarkIntent
import pro.respawn.flowmvi.benchmarks.setup.BenchmarkState

@Threads(Threads.MAX)
@Suppress("unused")
@State(Scope.Benchmark)
internal class FluxoBenchmark {
internal class FluxoIntentBenchmark {

lateinit var store: kt.fluxo.core.Store<BenchmarkIntent, BenchmarkState>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package pro.respawn.flowmvi.benchmarks.setup.fluxo

import kotlinx.benchmark.Benchmark
import kotlinx.coroutines.runBlocking
import kt.fluxo.core.annotation.ExperimentalFluxoApi
import kt.fluxo.core.closeAndWait
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State
import org.openjdk.jmh.annotations.Threads

@Threads(Threads.MAX)
@State(Scope.Benchmark)
class FluxoStartStopBenchmark {

@OptIn(ExperimentalFluxoApi::class)
@Benchmark
fun benchmark() = runBlocking {
val store = fluxoStore()
store.start().join()
store.closeAndWait()
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package pro.respawn.flowmvi.benchmarks.setup.optimized

import kotlinx.benchmark.TearDown
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Fork
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.Setup
import org.openjdk.jmh.annotations.State
import org.openjdk.jmh.annotations.Threads
import pro.respawn.flowmvi.api.Store
import pro.respawn.flowmvi.benchmarks.BenchmarkDefaults
import pro.respawn.flowmvi.benchmarks.setup.BenchmarkIntent
import pro.respawn.flowmvi.benchmarks.setup.BenchmarkState
import pro.respawn.flowmvi.dsl.collect

@Threads(Threads.MAX)
@Suppress("unused")
@State(Scope.Benchmark)
internal class OptimizedFMVIBenchmark {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package pro.respawn.flowmvi.benchmarks.setup.optimized

import kotlinx.benchmark.Benchmark
import kotlinx.coroutines.runBlocking
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State
import org.openjdk.jmh.annotations.Threads

@Threads(Threads.MAX)
@State(Scope.Benchmark)
internal class OptimizedFMVIStartStopBenchmark {

@Benchmark
fun benchmark() = runBlocking {
val store = optimizedStore()
store.start(this).awaitStartup()
store.closeAndWait()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import pro.respawn.flowmvi.api.ActionShareBehavior.Disabled
import pro.respawn.flowmvi.benchmarks.setup.BenchmarkIntent
import pro.respawn.flowmvi.benchmarks.setup.BenchmarkIntent.Increment
import pro.respawn.flowmvi.benchmarks.setup.BenchmarkState
import pro.respawn.flowmvi.dsl.StoreBuilder
import pro.respawn.flowmvi.dsl.store
import pro.respawn.flowmvi.plugins.reduce
import pro.respawn.flowmvi.plugins.reducePlugin

internal inline fun optimizedStore(
scope: CoroutineScope,
) = store<BenchmarkState, BenchmarkIntent, Nothing>(BenchmarkState(), scope) {
internal fun StoreBuilder<*, *, *>.config() {
configure {
logger = null
debuggable = false
Expand All @@ -23,11 +23,24 @@ internal inline fun optimizedStore(
onOverflow = BufferOverflow.DROP_OLDEST
intentCapacity = Channel.RENDEZVOUS
}
reduce {
when (it) {
is Increment -> updateStateImmediate {
copy(counter = counter + 1)
}
}

private val reduce = reducePlugin<BenchmarkState, BenchmarkIntent, Nothing> {
when (it) {
is Increment -> updateStateImmediate {
copy(counter = counter + 1)
}
}
}

internal inline fun optimizedStore(
scope: CoroutineScope,
) = store<BenchmarkState, BenchmarkIntent, Nothing>(BenchmarkState(), scope) {
config()
install(reduce)
}

internal inline fun optimizedStore() = store<BenchmarkState, BenchmarkIntent, Nothing>(BenchmarkState()) {
config()
install(reduce)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.Setup
import org.openjdk.jmh.annotations.State
import org.openjdk.jmh.annotations.Threads
import pro.respawn.flowmvi.api.Store
import pro.respawn.flowmvi.benchmarks.BenchmarkDefaults
import pro.respawn.flowmvi.benchmarks.setup.BenchmarkIntent
import pro.respawn.flowmvi.benchmarks.setup.BenchmarkState
import pro.respawn.flowmvi.dsl.collect

@Threads(Threads.MAX)
@Suppress("unused")
@State(Scope.Benchmark)
internal class ParallelFMVIBenchmark {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.Setup
import org.openjdk.jmh.annotations.State
import org.openjdk.jmh.annotations.Threads
import pro.respawn.flowmvi.benchmarks.BenchmarkDefaults
import pro.respawn.flowmvi.benchmarks.setup.BenchmarkIntent

@Threads(Threads.MAX)
@Suppress("unused")
@State(Scope.Benchmark)
internal class TraditionalMVIBenchmark {
Expand Down

0 comments on commit 8d6c5d9

Please sign in to comment.