Skip to content

Instantly share code, notes, and snippets.

@kibotu
Created February 6, 2020 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kibotu/eb0f60b222be4b78eeebcc602f6e911a to your computer and use it in GitHub Desktop.
Save kibotu/eb0f60b222be4b78eeebcc602f6e911a to your computer and use it in GitHub Desktop.
measureTime
inline fun <reified T> measureTime(message: String, min: Long? = null, block: () -> T): T {
val startTime = System.currentTimeMillis()
val result = block()
val blockRuntime = System.currentTimeMillis() - startTime
if (min != null) {
if (blockRuntime >= min) {
Logger.v("MeasureTime", "$message in ${blockRuntime}ms")
}
} else {
Logger.v("MeasureTime", "$message in ${blockRuntime}ms")
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment