Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions compose/animation/animation-benchmark/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ dependencies {

android {
compileSdk { version = release(37) }
defaultConfig {
minSdk { version = release(24) }
}

namespace = "androidx.compose.animation.benchmark"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ android {
compileSdk { version = release(37) }
buildTypes {
release {
minifyEnabled true
minifyEnabled = true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
}
benchmark {
initWith release
signingConfig = signingConfigs.debug
matchingFallbacks = ['release']
debuggable false
debuggable = false
}
}
}
Expand All @@ -44,8 +44,8 @@ dependencies {
implementation(project(":compose:foundation:foundation"))
implementation(project(":compose:material:material"))
implementation(project(":compose:material3:material3"))
implementation(project(":lifecycle:lifecycle-runtime"))
implementation(project(":lifecycle:lifecycle-common"))
implementation(project(":lifecycle:lifecycle-viewmodel"))
implementation("androidx.lifecycle:lifecycle-runtime:2.10.0")
implementation("androidx.lifecycle:lifecycle-common:2.10.0")
implementation("androidx.lifecycle:lifecycle-viewmodel:2.10.0")
implementation(project(":compose:runtime:runtime"))
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ android {
compileSdk {
version = release(37)
}
defaultConfig {
minSdk { version = release(24) }
}

buildTypes {
// This benchmark buildType is used for benchmarking, and should function like your
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2026 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.animation.benchmark

import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.runtime.Composable
import androidx.compose.testutils.LayeredComposeTestCase
import androidx.compose.testutils.benchmark.ComposeBenchmarkRule
import androidx.compose.testutils.benchmark.benchmarkFirstCompose
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@LargeTest
@RunWith(AndroidJUnit4::class)
class AnimateXAsStateBenchmark {
@get:Rule val rule = ComposeBenchmarkRule()

@Test fun animateFloat_compose() = rule.benchmarkFirstCompose(::AnimateFloatAsStateTestCase)
}

private class AnimateFloatAsStateTestCase : LayeredComposeTestCase() {
@Composable
override fun MeasuredContent() {
animateFloatAsState(targetValue = 0f)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2026 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.animation.benchmark

import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.core.updateTransition
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.testutils.LayeredComposeTestCase
import androidx.compose.testutils.ToggleableTestCase
import androidx.compose.testutils.benchmark.ComposeBenchmarkRule
import androidx.compose.testutils.benchmark.benchmarkFirstCompose
import androidx.compose.testutils.benchmark.benchmarkToFirstPixel
import androidx.compose.testutils.benchmark.toggleStateBenchmarkCompose
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@LargeTest
@RunWith(AndroidJUnit4::class)
class AnimatedContentBenchmark {
@get:Rule val rule = ComposeBenchmarkRule()

@Test fun compose() = rule.benchmarkFirstCompose(::AnimatedContentTestCase)

@Test fun firstPixel() = rule.benchmarkToFirstPixel(::AnimatedContentTestCase)

@Test
fun toggleState_compose() =
rule.toggleStateBenchmarkCompose(::AnimatedContentTestCase, assertOneRecomposition = false)
}

private class AnimatedContentTestCase : LayeredComposeTestCase(), ToggleableTestCase {
var state by mutableStateOf(true)

@Composable
override fun MeasuredContent() {
val transition = updateTransition(state)
transition.AnimatedContent { targetState ->
Box(Modifier.fillMaxSize().background(if (targetState) Color.Red else Color.Green))
}
}

override fun toggleState() {
state = !state
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2026 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.animation.benchmark

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.updateTransition
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.testutils.LayeredComposeTestCase
import androidx.compose.testutils.ToggleableTestCase
import androidx.compose.testutils.benchmark.ComposeBenchmarkRule
import androidx.compose.testutils.benchmark.benchmarkFirstCompose
import androidx.compose.testutils.benchmark.benchmarkToFirstPixel
import androidx.compose.testutils.benchmark.toggleStateBenchmarkCompose
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@LargeTest
@RunWith(AndroidJUnit4::class)
class AnimatedVisibilityBenchmark {
@get:Rule val rule = ComposeBenchmarkRule()

@Test fun compose() = rule.benchmarkFirstCompose(::AnimatedVisibilityTestCase)

@Test fun firstPixel() = rule.benchmarkToFirstPixel(::AnimatedVisibilityTestCase)

@Test
fun toggleState_compose() =
rule.toggleStateBenchmarkCompose(
::AnimatedVisibilityTestCase,
assertOneRecomposition = false,
)
}

private class AnimatedVisibilityTestCase : LayeredComposeTestCase(), ToggleableTestCase {
var state by mutableStateOf(true)

@Composable
override fun MeasuredContent() {
val transition = updateTransition(state)
transition.AnimatedVisibility(visible = { it }) {
Box(Modifier.fillMaxSize().background(Color.Red))
}
}

override fun toggleState() {
state = !state
}
}
Loading
Loading