Skip to content

Instantly share code, notes, and snippets.

@CDRussell
Created February 14, 2019 01:18
Show Gist options
  • Save CDRussell/3be5f183ba0431bf6339256c657d17bf to your computer and use it in GitHub Desktop.
Save CDRussell/3be5f183ba0431bf6339256c657d17bf to your computer and use it in GitHub Desktop.
inline fun <T> measureExecution(logMessage: String, logLevel: Int = Log.DEBUG, function: () -> T): T {
val startTime = System.nanoTime()
return function.invoke().also {
val difference = System.nanoTime() - startTime
Timber.log(logLevel, "$logMessage; took ${TimeUnit.NANOSECONDS.toMillis(difference)}ms")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment