Add a benchmark test for Resources.getIdentifier
In order to prevent unstable benchmark results because of cache, a random resource name with an expected value comes from Random.nextInt(10001).The range is from 0 to 10000. This patch creates 10001 color resources with the prefix "i_am_color_%x". The range is from "i_am_color_0" to "i_am_color_2710". The benchmark measures randomly accessing any of those resources. Test: atest --request-upload-result \ CorePerfTests:android.app.ResourcesPerfTest#getIdentifier Bug: 191487225 Change-Id: I357b43fda77e31b6d234233fd902eb8e4696301e
This commit is contained in:
parent
a83857b9e2
commit
ccb8c015b7
@ -1 +1,5 @@
|
|||||||
include /graphics/java/android/graphics/fonts/OWNERS
|
include /graphics/java/android/graphics/fonts/OWNERS
|
||||||
|
|
||||||
|
# Bug component: 568761
|
||||||
|
per-file /apct-tests/perftests/core/res/* = felkachang@google.com,zyy@google.com
|
||||||
|
|
||||||
|
10022
apct-tests/perftests/core/res/values/colors.xml
Normal file
10022
apct-tests/perftests/core/res/values/colors.xml
Normal file
File diff suppressed because it is too large
Load Diff
@ -37,6 +37,7 @@ import org.xmlpull.v1.XmlPullParser;
|
|||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Benchmarks for {@link android.content.res.Resources}.
|
* Benchmarks for {@link android.content.res.Resources}.
|
||||||
@ -222,4 +223,24 @@ public class ResourcesPerfTest {
|
|||||||
state.resumeTiming();
|
state.resumeTiming();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
|
public void getIdentifier() {
|
||||||
|
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
|
||||||
|
final Random random = new Random(System.currentTimeMillis());
|
||||||
|
final Context context = InstrumentationRegistry.getTargetContext();
|
||||||
|
final String packageName = context.getPackageName();
|
||||||
|
while (state.keepRunning()) {
|
||||||
|
state.pauseTiming();
|
||||||
|
final int expectedInteger = random.nextInt(10001);
|
||||||
|
final String expectedString = Integer.toHexString(expectedInteger);
|
||||||
|
final String entryName = "i_am_color_" + expectedString;
|
||||||
|
state.resumeTiming();
|
||||||
|
|
||||||
|
final int resIdentifier = mRes.getIdentifier(entryName, "color", packageName);
|
||||||
|
if (resIdentifier == 0) {
|
||||||
|
fail("Color \"" + entryName + "\" is not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user