This repository was archived by the owner on Oct 15, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +7
-14
lines changed
app/src/main/java/app/passwordstore/util Expand file tree Collapse file tree 1 file changed +7
-14
lines changed Original file line number Diff line number Diff line change 44package app.passwordstore.util
55
66import android.os.Looper
7- import android.os.SystemClock
7+ import kotlin.time.ExperimentalTime
8+ import kotlin.time.measureTime
89import 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
You can’t perform that action at this time.
0 commit comments