Henri Gourvest
10/20/2023, 11:01 AMIvan Matkov
10/20/2023, 3:40 PMHenri Gourvest
10/22/2023, 1:29 PM@Composable
fun EatFrames() {
var count by mutableStateOf(0)
var mark by mutableStateOf(TimeSource.Monotonic.markNow())
var rate by mutableStateOf(0)
val textMeasurer = rememberTextMeasurer()
val precision = 120
Canvas(Modifier.width(32.dp).height(24.dp).background(Color.Green)) {
if (count == precision) {
rate = (1000 * precision / mark.elapsedNow().toLong(DurationUnit.MILLISECONDS)).toInt()
count = 0
mark = TimeSource.Monotonic.markNow()
} else
count++
drawText(textMeasurer = textMeasurer, text = "$rate")
}
}