diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-04-21 16:35:52 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-04-21 16:37:18 +0200 |
| commit | 62678b2890a7f3640836b99ca2fec9efd7485929 (patch) | |
| tree | dc6d6e8bb495c019990513511d7ff042afde0f05 /simulator/opendc-simulator/opendc-simulator-resources/src/jmh | |
| parent | 1c0568c31d60d4e690b4b9aec2e14f660b72a5c8 (diff) | |
simulator: Migrate to SimulationCoroutineDispatcher
This change migrates the remainder of the codebase to the
SimulationCoroutineDispatcher implementation.
Diffstat (limited to 'simulator/opendc-simulator/opendc-simulator-resources/src/jmh')
| -rw-r--r-- | simulator/opendc-simulator/opendc-simulator-resources/src/jmh/kotlin/org/opendc/simulator/resources/SimResourceBenchmarks.kt | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/simulator/opendc-simulator/opendc-simulator-resources/src/jmh/kotlin/org/opendc/simulator/resources/SimResourceBenchmarks.kt b/simulator/opendc-simulator/opendc-simulator-resources/src/jmh/kotlin/org/opendc/simulator/resources/SimResourceBenchmarks.kt index ab0abe23..beda3eaa 100644 --- a/simulator/opendc-simulator/opendc-simulator-resources/src/jmh/kotlin/org/opendc/simulator/resources/SimResourceBenchmarks.kt +++ b/simulator/opendc-simulator/opendc-simulator-resources/src/jmh/kotlin/org/opendc/simulator/resources/SimResourceBenchmarks.kt @@ -24,12 +24,10 @@ package org.opendc.simulator.resources import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.launch -import kotlinx.coroutines.test.TestCoroutineScope -import kotlinx.coroutines.test.runBlockingTest -import org.opendc.simulator.core.DelayControllerClockAdapter +import org.opendc.simulator.core.SimulationCoroutineScope +import org.opendc.simulator.core.runBlockingSimulation import org.opendc.utils.TimerScheduler import org.openjdk.jmh.annotations.* -import java.time.Clock import java.util.concurrent.TimeUnit @State(Scope.Thread) @@ -38,15 +36,13 @@ import java.util.concurrent.TimeUnit @Measurement(iterations = 5, time = 3, timeUnit = TimeUnit.SECONDS) @OptIn(ExperimentalCoroutinesApi::class) class SimResourceBenchmarks { - private lateinit var scope: TestCoroutineScope - private lateinit var clock: Clock + private lateinit var scope: SimulationCoroutineScope private lateinit var scheduler: TimerScheduler<Any> @Setup fun setUp() { - scope = TestCoroutineScope() - clock = DelayControllerClockAdapter(scope) - scheduler = TimerScheduler(scope.coroutineContext, clock) + scope = SimulationCoroutineScope() + scheduler = TimerScheduler(scope.coroutineContext, scope.clock) } @State(Scope.Thread) @@ -61,38 +57,38 @@ class SimResourceBenchmarks { @Benchmark fun benchmarkSource(state: Workload) { - return scope.runBlockingTest { + return scope.runBlockingSimulation { val provider = SimResourceSource(4200.0, clock, scheduler) - return@runBlockingTest provider.consume(state.consumers[0]) + return@runBlockingSimulation provider.consume(state.consumers[0]) } } @Benchmark fun benchmarkForwardOverhead(state: Workload) { - return scope.runBlockingTest { + return scope.runBlockingSimulation { val provider = SimResourceSource(4200.0, clock, scheduler) val forwarder = SimResourceForwarder() provider.startConsumer(forwarder) - return@runBlockingTest forwarder.consume(state.consumers[0]) + return@runBlockingSimulation forwarder.consume(state.consumers[0]) } } @Benchmark fun benchmarkSwitchMaxMinSingleConsumer(state: Workload) { - return scope.runBlockingTest { + return scope.runBlockingSimulation { val switch = SimResourceSwitchMaxMin(clock) switch.addInput(SimResourceSource(3000.0, clock, scheduler)) switch.addInput(SimResourceSource(3000.0, clock, scheduler)) val provider = switch.addOutput(3500.0) - return@runBlockingTest provider.consume(state.consumers[0]) + return@runBlockingSimulation provider.consume(state.consumers[0]) } } @Benchmark fun benchmarkSwitchMaxMinTripleConsumer(state: Workload) { - return scope.runBlockingTest { + return scope.runBlockingSimulation { val switch = SimResourceSwitchMaxMin(clock) switch.addInput(SimResourceSource(3000.0, clock, scheduler)) @@ -109,20 +105,20 @@ class SimResourceBenchmarks { @Benchmark fun benchmarkSwitchExclusiveSingleConsumer(state: Workload) { - return scope.runBlockingTest { + return scope.runBlockingSimulation { val switch = SimResourceSwitchExclusive() switch.addInput(SimResourceSource(3000.0, clock, scheduler)) switch.addInput(SimResourceSource(3000.0, clock, scheduler)) val provider = switch.addOutput(3500.0) - return@runBlockingTest provider.consume(state.consumers[0]) + return@runBlockingSimulation provider.consume(state.consumers[0]) } } @Benchmark fun benchmarkSwitchExclusiveTripleConsumer(state: Workload) { - return scope.runBlockingTest { + return scope.runBlockingSimulation { val switch = SimResourceSwitchExclusive() switch.addInput(SimResourceSource(3000.0, clock, scheduler)) |
