From 75912a3bc1dbc69cd2717a5fdb504438d4bdc0c4 Mon Sep 17 00:00:00 2001 From: Igor Demin Date: Mon, 24 Jul 2023 21:40:12 +0200 Subject: [PATCH] Benchmarks. Calculate median. Startup --- .../src/commonMain/kotlin/Benchmarks.kt | 2 -- .../commonMain/kotlin/MeasureComposable.kt | 25 ++++++++----------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/benchmarks/ios/jvm-vs-kotlin-native/src/commonMain/kotlin/Benchmarks.kt b/benchmarks/ios/jvm-vs-kotlin-native/src/commonMain/kotlin/Benchmarks.kt index d8c452c99d..d69a8f6264 100644 --- a/benchmarks/ios/jvm-vs-kotlin-native/src/commonMain/kotlin/Benchmarks.kt +++ b/benchmarks/ios/jvm-vs-kotlin-native/src/commonMain/kotlin/Benchmarks.kt @@ -8,7 +8,5 @@ fun runBenchmark(name: String, frameCount: Int, content: @Composable () -> Unit) } fun runBenchmarks() { - runBenchmark("AnimatedVisibility", 2000) { AnimatedVisibility() } runBenchmark("LazyGrid",40) { LazyGrid() } - runBenchmark("VisualEffects",20) { NYContent() } } \ No newline at end of file diff --git a/benchmarks/ios/jvm-vs-kotlin-native/src/commonMain/kotlin/MeasureComposable.kt b/benchmarks/ios/jvm-vs-kotlin-native/src/commonMain/kotlin/MeasureComposable.kt index 9fe924b2cd..c373ddf066 100644 --- a/benchmarks/ios/jvm-vs-kotlin-native/src/commonMain/kotlin/MeasureComposable.kt +++ b/benchmarks/ios/jvm-vs-kotlin-native/src/commonMain/kotlin/MeasureComposable.kt @@ -17,26 +17,23 @@ fun measureComposable( frameCount: Int = 100, content: @Composable () -> Unit ): Duration { + val times = kotlin.time.measureTime { + val scene = ComposeScene() + try { + scene.setContent(content) + scene.constraints = Constraints.fixed(width, height) + val surface = org.jetbrains.skia.Surface.makeNull(width, height) - val scene = ComposeScene() - val times = try { - scene.setContent(content) - scene.constraints = Constraints.fixed(width, height) - val surface = org.jetbrains.skia.Surface.makeNull(width, height) - - (1..200).map { - kotlin.time.measureTime { var nanoTime = 0L - repeat(frameCount) { + repeat(1) { scene.render(surface.canvas, nanoTime) nanoTime += nanosPerFrame } - }.inWholeMilliseconds + } finally { + scene.close() } - } finally { - scene.close() - } - return times.median().toDuration(DurationUnit.MILLISECONDS) + }.inWholeMilliseconds + return times.toDuration(DurationUnit.MILLISECONDS) } private fun List.median() = sorted()[size/ 2] \ No newline at end of file