Skip to content

Instantly share code, notes, and snippets.

@sajjadyousefnia
Created June 30, 2024 11:10
Show Gist options
  • Save sajjadyousefnia/65262699f02c204b253cfba04b9f860f to your computer and use it in GitHub Desktop.
Save sajjadyousefnia/65262699f02c204b253cfba04b9f860f to your computer and use it in GitHub Desktop.
fun calculateDownloadSpeed(
oldBytes: Long, newBytes: Long, oldTimeMillis: Long, newTimeMillis: Long
): Double {
val downloadedBytes = newBytes - oldBytes
val timeSeconds = (newTimeMillis - oldTimeMillis) / 1000.0
val speedBytesPerSecond = downloadedBytes / timeSeconds
return speedBytesPerSecond / 1_048_576 // Convert to megabytes per second
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment