mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-08-30 22:05:19 +00:00
refactor(app): switch logExecutionTime
to kotlin.time.measureTime
This commit is contained in:
@@ -4,26 +4,19 @@
|
|||||||
package app.passwordstore.util
|
package app.passwordstore.util
|
||||||
|
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.os.SystemClock
|
import kotlin.time.ExperimentalTime
|
||||||
|
import kotlin.time.measureTime
|
||||||
import logcat.logcat
|
import logcat.logcat
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Small helper to execute a given [block] and log the time it took to execute it. Intended for use
|
* 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.
|
* 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 {
|
@OptIn(ExperimentalTime::class)
|
||||||
val start = SystemClock.uptimeMillis()
|
inline fun <T> logExecutionTime(tag: String, crossinline block: () -> T): T {
|
||||||
val res = block()
|
val res: T
|
||||||
val end = SystemClock.uptimeMillis()
|
val duration = measureTime { res = block() }
|
||||||
logcat(tag) { "Finished in ${end - start}ms" }
|
logcat(tag) { "Finished in ${duration.inWholeMilliseconds}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" }
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user