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 4
4
package app.passwordstore.util
5
5
6
6
import android.os.Looper
7
- import android.os.SystemClock
7
+ import kotlin.time.ExperimentalTime
8
+ import kotlin.time.measureTime
8
9
import logcat.logcat
9
10
10
11
/* *
11
12
* Small helper to execute a given [block] and log the time it took to execute it. Intended for use
12
13
* in day-to-day perf investigations and code using it should probably not be shipped.
13
14
*/
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" }
27
20
return res
28
21
}
29
22
You can’t perform that action at this time.
0 commit comments