Skip to content

Instantly share code, notes, and snippets.

@adil-hussain-84
Created December 8, 2023 14:15
Show Gist options
  • Save adil-hussain-84/87d278136fe56babcc9dd209d3974102 to your computer and use it in GitHub Desktop.
Save adil-hussain-84/87d278136fe56babcc9dd209d3974102 to your computer and use it in GitHub Desktop.
Android class that helps log the number of milliseconds that have elapsed since a reference point.
class ElapsedTimeLogger(private val tag: String = ElapsedTimeLogger::class.simpleName!!) {
private var startTime = SystemClock.elapsedRealtime()
/**
* Logs the number of milliseconds that have elapsed since this [ElapsedTimeLogger] was initialised.
*
* The logs are sent to log output (i.e. Logcat) as a debug message.
*/
fun logElapsedTime() {
val currentTime = SystemClock.elapsedRealtime()
val elapsedTime = currentTime - startTime
Log.d(tag, "Elapsed time in milliseconds = $elapsedTime")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment