Skip to content

Commit

Permalink
chore: fix benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Nek-12 committed Dec 8, 2024
1 parent 70c11bb commit 773279c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion benchmarks/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ kotlin {
tvOs = false,
windows = false,
wasmJs = false,
jvm = true,
)
}
tasks.withType<JavaExec>().configureEach {
Expand All @@ -47,7 +48,7 @@ benchmark {
named("main") {
iterations = 100
warmups = 20
iterationTime = 100
iterationTime = 500
iterationTimeUnit = "ms"
outputTimeUnit = "us"
mode = "avgt" // "thrpt" - throughput, "avgt" - average
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.yield
import pro.respawn.flowmvi.benchmarks.setup.BenchmarkIntent.Increment
import pro.respawn.flowmvi.benchmarks.setup.atomic.atomicParallelStore
import pro.respawn.flowmvi.benchmarks.setup.atomic.atomicStore

/**
* run an infinite process for profiling
*/
fun main() = runBlocking {
println(ProcessHandle.current().pid())
val store = atomicParallelStore(this)
val store = atomicStore(this)
launch {
while (isActive) {
store.intent(Increment)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class AtomicFMVIBenchmark {

@Benchmark
fun benchmark() = runBlocking {
val store = atomicParallelStore(this)
val store = atomicStore(this)
repeat(BenchmarkDefaults.intentsPerIteration) {
store.emit(BenchmarkIntent.Increment)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.channels.Channel
import pro.respawn.flowmvi.api.ActionShareBehavior
import pro.respawn.flowmvi.api.StateStrategy
import pro.respawn.flowmvi.benchmarks.setup.BenchmarkIntent
import pro.respawn.flowmvi.benchmarks.setup.BenchmarkIntent.Increment
import pro.respawn.flowmvi.benchmarks.setup.BenchmarkState
Expand All @@ -15,14 +16,14 @@ private fun StoreBuilder<*, *, *>.config() = configure {
logger = null
debuggable = false
actionShareBehavior = ActionShareBehavior.Disabled
atomicStateUpdates = true
stateStrategy = StateStrategy.Atomic(reentrant = false)
parallelIntents = false
verifyPlugins = false
onOverflow = BufferOverflow.SUSPEND
intentCapacity = Channel.UNLIMITED
}

internal fun atomicParallelStore(
internal fun atomicStore(
scope: CoroutineScope
) = store<BenchmarkState, BenchmarkIntent, Nothing>(BenchmarkState(), scope) {
config()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pro.respawn.flowmvi.benchmarks.setup.fluxo

import kotlinx.coroutines.flow.first
import kotlinx.coroutines.runBlocking
import kt.fluxo.core.annotation.ExperimentalFluxoApi
import kt.fluxo.core.closeAndWait
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Scope
Expand All @@ -15,6 +16,7 @@ import pro.respawn.flowmvi.benchmarks.setup.BenchmarkIntent
@State(Scope.Benchmark)
internal class FluxoIntentBenchmark {

@OptIn(ExperimentalFluxoApi::class)
@Benchmark
fun benchmark() = runBlocking {
val store = fluxoStore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.channels.Channel
import pro.respawn.flowmvi.api.ActionShareBehavior.Disabled
import pro.respawn.flowmvi.api.StateStrategy.Immediate
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.dsl.updateStateImmediate
import pro.respawn.flowmvi.plugins.reduce
import pro.respawn.flowmvi.plugins.reducePlugin

internal fun StoreBuilder<*, *, *>.config() {
configure {
logger = null
debuggable = false
actionShareBehavior = Disabled
atomicStateUpdates = false
stateStrategy = Immediate
parallelIntents = false
verifyPlugins = false
onOverflow = BufferOverflow.SUSPEND
Expand Down

0 comments on commit 773279c

Please sign in to comment.