diff --git a/core/koin-core/src/commonMain/kotlin/org/koin/core/time/Measure.kt b/core/koin-core/src/commonMain/kotlin/org/koin/core/time/Measure.kt index e8ad5be55..785e6fe60 100644 --- a/core/koin-core/src/commonMain/kotlin/org/koin/core/time/Measure.kt +++ b/core/koin-core/src/commonMain/kotlin/org/koin/core/time/Measure.kt @@ -15,6 +15,7 @@ */ package org.koin.core.time +import kotlin.time.DurationUnit import kotlin.time.ExperimentalTime import kotlin.time.measureTime import kotlin.time.measureTimedValue @@ -28,12 +29,7 @@ import kotlin.time.measureTimedValue @OptIn(ExperimentalTime::class) fun measureDuration(code: () -> Unit): Double { - return measureTime(code).inMilliseconds -} - -fun measureDuration(message: String, code: () -> Unit) { - val time = measureDuration(code) - println("$message - $time ms") + return measureTime(code).toDouble(DurationUnit.MILLISECONDS) } /** @@ -42,11 +38,5 @@ fun measureDuration(message: String, code: () -> Unit) { @OptIn(ExperimentalTime::class) fun measureDurationForResult(code: () -> T): Pair { val result = measureTimedValue(code) - return Pair(result.value, result.duration.inMilliseconds) -} - -fun measureDurationForResult(message: String, code: () -> T): T { - val (result, time) = measureDurationForResult(code) - println("$message - $time ms") - return result + return Pair(result.value, result.duration.toDouble(DurationUnit.MILLISECONDS)) } \ No newline at end of file diff --git a/core/koin-core/src/commonTest/kotlin/org/koin/core/ScopeTest.kt b/core/koin-core/src/commonTest/kotlin/org/koin/core/ScopeTest.kt index e24674379..09be0241c 100644 --- a/core/koin-core/src/commonTest/kotlin/org/koin/core/ScopeTest.kt +++ b/core/koin-core/src/commonTest/kotlin/org/koin/core/ScopeTest.kt @@ -1,16 +1,11 @@ package org.koin.core -import kotlin.test.assertEquals -import org.junit.Assert.assertNotNull -import org.junit.Assert.assertNull -import org.junit.Assert.assertTrue -import kotlin.test.fail -import kotlin.test.Test import org.koin.Simple import org.koin.core.error.ClosedScopeException import org.koin.core.qualifier.named import org.koin.dsl.koinApplication import org.koin.dsl.module +import kotlin.test.* class ScopeTest { diff --git a/core/koin-core/src/commonTest/kotlin/org/koin/core/SetterInjectTest.kt b/core/koin-core/src/commonTest/kotlin/org/koin/core/SetterInjectTest.kt index a81c73812..ab1cda2ee 100644 --- a/core/koin-core/src/commonTest/kotlin/org/koin/core/SetterInjectTest.kt +++ b/core/koin-core/src/commonTest/kotlin/org/koin/core/SetterInjectTest.kt @@ -11,6 +11,8 @@ import org.koin.core.time.measureDuration import org.koin.dsl.module import org.koin.ext.inject import kotlin.test.Test +import kotlin.time.DurationUnit +import kotlin.time.measureTime class B : KoinScopeComponent { override val scope: Scope by lazy { createScope(this) } @@ -68,4 +70,10 @@ class PlayTest { stopKoin() } +} + +fun measureDuration(msg : String, code: () -> Unit): Double { + val duration = measureDuration(code) + println(msg) + return duration } \ No newline at end of file diff --git a/core/koin-core/src/commonTest/kotlin/org/koin/perfs/PerfsTest.kt b/core/koin-core/src/commonTest/kotlin/org/koin/perfs/PerfsTest.kt index d2440f55f..9b6afc59c 100644 --- a/core/koin-core/src/commonTest/kotlin/org/koin/perfs/PerfsTest.kt +++ b/core/koin-core/src/commonTest/kotlin/org/koin/perfs/PerfsTest.kt @@ -1,6 +1,5 @@ package org.koin.perfs -import kotlin.test.Test import org.koin.core.A import org.koin.core.annotation.KoinInternalApi import org.koin.core.definition.Definitions @@ -10,6 +9,7 @@ import org.koin.core.time.measureDurationForResult import org.koin.dsl.koinApplication import org.koin.dsl.module import org.koin.test.assertDefinitionsCount +import kotlin.test.Test class PerfsTest { @@ -42,7 +42,8 @@ class PerfsTest { A::class, definition = { A() }, options = Options(), - scopeQualifier = ScopeDefinition.ROOT_SCOPE_QUALIFIER) + scopeQualifier = ScopeDefinition.ROOT_SCOPE_QUALIFIER + ) ) app.close() } @@ -89,4 +90,10 @@ class PerfsTest { app.close() } +} + +fun measureDurationForResult(msg: String, code: () -> T): T { + val result = measureDurationForResult(code) + println(msg) + return result.first } \ No newline at end of file diff --git a/examples/coffee-maker/src/main/kotlin/org/koin/example/CoffeeApp.kt b/examples/coffee-maker/src/main/kotlin/org/koin/example/CoffeeApp.kt index 46578969d..0a1cd0c2a 100644 --- a/examples/coffee-maker/src/main/kotlin/org/koin/example/CoffeeApp.kt +++ b/examples/coffee-maker/src/main/kotlin/org/koin/example/CoffeeApp.kt @@ -19,4 +19,10 @@ fun main() { measureDuration("Got Coffee") { coffeeShop.maker.brew() } +} + +fun measureDuration(msg : String, code: () -> Unit): Double { + val duration = measureDuration(code) + println(msg) + return duration } \ No newline at end of file