Skip to content

Instantly share code, notes, and snippets.

@joaorbrandao
Created December 30, 2022 09:11
Show Gist options
  • Save joaorbrandao/4e31d43f5fd3f43d1890e64c69d3a8c0 to your computer and use it in GitHub Desktop.
Save joaorbrandao/4e31d43f5fd3f43d1890e64c69d3a8c0 to your computer and use it in GitHub Desktop.
Percentil calculations
fun List<Long>.p50(): Long {
val sorted = sorted()
val p50Position = floor(sorted.size * 0.5).toInt()
return sorted[p50Position]
}
fun List<Long>.p90(): Long {
val sorted = sorted()
val p90Position = floor(sorted.size * 0.9).toInt()
return sorted[p90Position]
}
fun List<Long>.p99(): Long {
val sorted = sorted()
val p99Position = floor(sorted.size * 0.99).toInt()
return sorted[p99Position]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment