aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-10-09 20:05:40 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2022-10-09 20:05:40 +0530
commiteb5e9bdffa5db7e74beab5b8148ea97a6d2dbf30 (patch)
tree244a61b59827c1c3797597971be38a09fe0da26f /app
parentc866bb9fb195eb77b62221212a2b2f158ae7ae0e (diff)
refactor(app): switch `logExecutionTime` to `kotlin.time.measureTime`
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/app/passwordstore/util/Perf.kt21
1 files changed, 7 insertions, 14 deletions
diff --git a/app/src/main/java/app/passwordstore/util/Perf.kt b/app/src/main/java/app/passwordstore/util/Perf.kt
index 8b3769e9..c56410f9 100644
--- a/app/src/main/java/app/passwordstore/util/Perf.kt
+++ b/app/src/main/java/app/passwordstore/util/Perf.kt
@@ -4,26 +4,19 @@
package app.passwordstore.util
import android.os.Looper
-import android.os.SystemClock
+import kotlin.time.ExperimentalTime
+import kotlin.time.measureTime
import logcat.logcat
/**
* Small helper to execute a given [block] and log the time it took to execute it. Intended for use
* in day-to-day perf investigations and code using it should probably not be shipped.
*/
-suspend fun <T> logExecutionTime(tag: String, block: suspend () -> T): T {
- val start = SystemClock.uptimeMillis()
- val res = block()
- val end = SystemClock.uptimeMillis()
- logcat(tag) { "Finished in ${end - start}ms" }
- return res
-}
-
-fun <T> logExecutionTimeBlocking(tag: String, block: () -> T): T {
- val start = SystemClock.uptimeMillis()
- val res = block()
- val end = SystemClock.uptimeMillis()
- logcat(tag) { "Finished in ${end - start}ms" }
+@OptIn(ExperimentalTime::class)
+inline fun <T> logExecutionTime(tag: String, crossinline block: () -> T): T {
+ val res: T
+ val duration = measureTime { res = block() }
+ logcat(tag) { "Finished in ${duration.inWholeMilliseconds}ms" }
return res
}