Skip to content

Instantly share code, notes, and snippets.

@ZahidRasheed
Created July 21, 2019 17:20
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 ZahidRasheed/73af9587f3ef646b168ca0137bf2b261 to your computer and use it in GitHub Desktop.
Save ZahidRasheed/73af9587f3ef646b168ca0137bf2b261 to your computer and use it in GitHub Desktop.
Measure time
inline fun <T> measureTimeMillis(loggingFunction: (Long) -> Unit,
function: () -> T): T {
val startTime = System.currentTimeMillis()
val result: T = function.invoke()
loggingFunction.invoke(System.currentTimeMillis() - startTime)
return result
}
val file: File =
measureTimeMillis({ time -> Log.d(TAG, "Read and decode took $time") }) {
readAndDecodeFile()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment