Loading PREUPLOAD.cfg +1 −2 Original line number Diff line number Diff line [Hook Scripts] checkstyle_hook = ${REPO_ROOT}/prebuilts/checkstyle/checkstyle.py --sha ${PREUPLOAD_COMMIT} -fw core/java/android/ -fw core/ graphics/java/android core/tests/coretests/src/android/ packages/PrintRecommendationService/ packages/PrintSpooler/ packages/PackageInstaller/ Loading core/tests/benchmarks/src/android/content/res/ResourcesBenchmark.java→apct-tests/perftests/core/src/android/app/ResourcesPerfTest.java +107 −0 Original line number Diff line number Diff line /* * Copyright (C) 2015 The Android Open Source Project * Copyright (C) 2018 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. Loading @@ -14,19 +14,33 @@ * limitations under the License. */ package android.content.res; package android.app; import android.util.AttributeSet; import android.util.Xml; import static org.junit.Assert.fail; import com.android.internal.R; import android.content.res.AssetManager; import android.content.res.Resources; import android.content.res.XmlResourceParser; import android.perftests.utils.BenchmarkState; import android.perftests.utils.PerfStatusReporter; import android.support.test.filters.LargeTest; import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import com.google.caliper.AfterExperiment; import com.google.caliper.BeforeExperiment; import java.io.IOException; public class ResourcesBenchmark { /** * Benchmarks for {@link android.content.res.Resources}. */ @LargeTest public class ResourcesPerfTest { @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); private AssetManager mAsset; private Resources mRes; Loading @@ -36,8 +50,8 @@ public class ResourcesBenchmark { private int mIntegerId; private int mLayoutId; @BeforeExperiment protected void setUp() { @Before public void setUp() { mAsset = new AssetManager(); mAsset.addAssetPath("/system/framework/framework-res.apk"); mRes = new Resources(mAsset, null, null); Loading @@ -48,38 +62,45 @@ public class ResourcesBenchmark { mLayoutId = mRes.getIdentifier("two_line_list_item", "layout", "android"); } @AfterExperiment protected void tearDown() { @After public void tearDown() { mAsset.close(); } public void timeGetString(int reps) { for (int i = 0; i < reps; i++) { @Test public void getText() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { mRes.getText(mTextId); } } public void timeGetColor(int reps) { for (int i = 0; i < reps; i++) { @Test public void getColor() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { mRes.getColor(mColorId, null); } } public void timeGetInteger(int reps) { for (int i = 0; i < reps; i++) { @Test public void getInteger() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { mRes.getInteger(mIntegerId); } } public void timeGetLayoutAndTraverse(int reps) throws Exception { for (int i = 0; i < reps; i++) { final XmlResourceParser parser = mRes.getLayout(mLayoutId); try { @Test public void getLayoutAndTravese() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { try (XmlResourceParser parser = mRes.getLayout(mLayoutId)) { while (parser.next() != XmlPullParser.END_DOCUMENT) { // Walk the entire tree } } finally { parser.close(); } catch (IOException | XmlPullParserException exception) { fail("Parsing of the layout failed. Something is really broken"); } } } Loading Loading
PREUPLOAD.cfg +1 −2 Original line number Diff line number Diff line [Hook Scripts] checkstyle_hook = ${REPO_ROOT}/prebuilts/checkstyle/checkstyle.py --sha ${PREUPLOAD_COMMIT} -fw core/java/android/ -fw core/ graphics/java/android core/tests/coretests/src/android/ packages/PrintRecommendationService/ packages/PrintSpooler/ packages/PackageInstaller/ Loading
core/tests/benchmarks/src/android/content/res/ResourcesBenchmark.java→apct-tests/perftests/core/src/android/app/ResourcesPerfTest.java +107 −0 Original line number Diff line number Diff line /* * Copyright (C) 2015 The Android Open Source Project * Copyright (C) 2018 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. Loading @@ -14,19 +14,33 @@ * limitations under the License. */ package android.content.res; package android.app; import android.util.AttributeSet; import android.util.Xml; import static org.junit.Assert.fail; import com.android.internal.R; import android.content.res.AssetManager; import android.content.res.Resources; import android.content.res.XmlResourceParser; import android.perftests.utils.BenchmarkState; import android.perftests.utils.PerfStatusReporter; import android.support.test.filters.LargeTest; import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import com.google.caliper.AfterExperiment; import com.google.caliper.BeforeExperiment; import java.io.IOException; public class ResourcesBenchmark { /** * Benchmarks for {@link android.content.res.Resources}. */ @LargeTest public class ResourcesPerfTest { @Rule public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); private AssetManager mAsset; private Resources mRes; Loading @@ -36,8 +50,8 @@ public class ResourcesBenchmark { private int mIntegerId; private int mLayoutId; @BeforeExperiment protected void setUp() { @Before public void setUp() { mAsset = new AssetManager(); mAsset.addAssetPath("/system/framework/framework-res.apk"); mRes = new Resources(mAsset, null, null); Loading @@ -48,38 +62,45 @@ public class ResourcesBenchmark { mLayoutId = mRes.getIdentifier("two_line_list_item", "layout", "android"); } @AfterExperiment protected void tearDown() { @After public void tearDown() { mAsset.close(); } public void timeGetString(int reps) { for (int i = 0; i < reps; i++) { @Test public void getText() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { mRes.getText(mTextId); } } public void timeGetColor(int reps) { for (int i = 0; i < reps; i++) { @Test public void getColor() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { mRes.getColor(mColorId, null); } } public void timeGetInteger(int reps) { for (int i = 0; i < reps; i++) { @Test public void getInteger() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { mRes.getInteger(mIntegerId); } } public void timeGetLayoutAndTraverse(int reps) throws Exception { for (int i = 0; i < reps; i++) { final XmlResourceParser parser = mRes.getLayout(mLayoutId); try { @Test public void getLayoutAndTravese() { final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); while (state.keepRunning()) { try (XmlResourceParser parser = mRes.getLayout(mLayoutId)) { while (parser.next() != XmlPullParser.END_DOCUMENT) { // Walk the entire tree } } finally { parser.close(); } catch (IOException | XmlPullParserException exception) { fail("Parsing of the layout failed. Something is really broken"); } } } Loading