diff options
author | Yeabkal Wubshit <yeabkal@google.com> | 2023-09-14 20:44:16 -0700 |
---|---|---|
committer | Yeabkal Wubshit <yeabkal@google.com> | 2023-09-21 21:30:13 +0000 |
commit | 668e17494cd1847bdca32b11edb5adb149028295 (patch) | |
tree | ced07dce618c548b226c6fe0c62f77050880b074 /apct-tests | |
parent | c05944b3663fec1c87781c8f1dd154c4d351558b (diff) | |
download | base-668e17494cd1847bdca32b11edb5adb149028295.tar.gz |
Add ViewConfigurationPerfTest
Created two simple benchmark tests to measure performance of
ViewConfiguration#get.
Bug: 299587011
Test: atest ViewConfigurationPerfTest
Change-Id: If502a4acb6bc6080af134675e610a76df59c538a
Diffstat (limited to 'apct-tests')
-rw-r--r-- | apct-tests/perftests/core/src/android/view/ViewConfigurationPerfTest.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/apct-tests/perftests/core/src/android/view/ViewConfigurationPerfTest.java b/apct-tests/perftests/core/src/android/view/ViewConfigurationPerfTest.java new file mode 100644 index 000000000000..7a7250b9e910 --- /dev/null +++ b/apct-tests/perftests/core/src/android/view/ViewConfigurationPerfTest.java @@ -0,0 +1,61 @@ +/* + * Copyright 2023 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 android.view; + +import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; + +import android.content.Context; + +import androidx.benchmark.BenchmarkState; +import androidx.benchmark.junit4.BenchmarkRule; +import androidx.test.filters.SmallTest; + +import org.junit.Rule; +import org.junit.Test; + +@SmallTest +public class ViewConfigurationPerfTest { + @Rule + public final BenchmarkRule mBenchmarkRule = new BenchmarkRule(); + + private final Context mContext = getInstrumentation().getTargetContext(); + + @Test + public void testGet_newViewConfiguration() { + final BenchmarkState state = mBenchmarkRule.getState(); + + while (state.keepRunning()) { + state.pauseTiming(); + // Reset cache so that `ViewConfiguration#get` creates a new instance. + ViewConfiguration.resetCacheForTesting(); + state.resumeTiming(); + + ViewConfiguration.get(mContext); + } + } + + @Test + public void testGet_cachedViewConfiguration() { + final BenchmarkState state = mBenchmarkRule.getState(); + // Do `get` once to make sure there's something cached. + ViewConfiguration.get(mContext); + + while (state.keepRunning()) { + ViewConfiguration.get(mContext); + } + } +} |