From 766b41566f4cf8297202147d789e135a76041ed4 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Sun, 22 Aug 2021 13:21:53 +0200 Subject: perf(simulator): Prevent counter update without work This change implements a performance improvement by preventing updates on the resource counters in case no work was performed in the last cycle. --- .../org/opendc/simulator/resources/SimAbstractResourceProvider.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimAbstractResourceProvider.kt b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimAbstractResourceProvider.kt index c1b1450e..2ceb1e3c 100644 --- a/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimAbstractResourceProvider.kt +++ b/opendc-simulator/opendc-simulator-resources/src/main/kotlin/org/opendc/simulator/resources/SimAbstractResourceProvider.kt @@ -88,6 +88,10 @@ public abstract class SimAbstractResourceProvider( * Update the counters of the resource provider. */ protected fun updateCounters(ctx: SimResourceContext, work: Double) { + if (work <= 0.0) { + return + } + val counters = _counters val remainingWork = ctx.remainingWork counters.demand += work -- cgit v1.2.3