Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit eb5e9bd

Browse files
committed
refactor(app): switch logExecutionTime to kotlin.time.measureTime
1 parent c866bb9 commit eb5e9bd

File tree

1 file changed

+7
-14
lines changed
  • app/src/main/java/app/passwordstore/util

1 file changed

+7
-14
lines changed

app/src/main/java/app/passwordstore/util/Perf.kt

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,19 @@
44
package app.passwordstore.util
55

66
import android.os.Looper
7-
import android.os.SystemClock
7+
import kotlin.time.ExperimentalTime
8+
import kotlin.time.measureTime
89
import logcat.logcat
910

1011
/**
1112
* Small helper to execute a given [block] and log the time it took to execute it. Intended for use
1213
* in day-to-day perf investigations and code using it should probably not be shipped.
1314
*/
14-
suspend fun <T> logExecutionTime(tag: String, block: suspend () -> T): T {
15-
val start = SystemClock.uptimeMillis()
16-
val res = block()
17-
val end = SystemClock.uptimeMillis()
18-
logcat(tag) { "Finished in ${end - start}ms" }
19-
return res
20-
}
21-
22-
fun <T> logExecutionTimeBlocking(tag: String, block: () -> T): T {
23-
val start = SystemClock.uptimeMillis()
24-
val res = block()
25-
val end = SystemClock.uptimeMillis()
26-
logcat(tag) { "Finished in ${end - start}ms" }
15+
@OptIn(ExperimentalTime::class)
16+
inline fun <T> logExecutionTime(tag: String, crossinline block: () -> T): T {
17+
val res: T
18+
val duration = measureTime { res = block() }
19+
logcat(tag) { "Finished in ${duration.inWholeMilliseconds}ms" }
2720
return res
2821
}
2922

0 commit comments

Comments
 (0)