diff options
author | Jeff Sharkey <jsharkey@android.com> | 2015-11-02 18:39:45 -0800 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2015-11-02 19:49:11 -0800 |
commit | 46cfd93aa22b5a4acab4626c140415eef922445c (patch) | |
tree | 2a991a8db2b6579bae58047d1849b5e863f6c1a2 /core/tests/benchmarks | |
parent | 0a7a913683cb52cc847d52e4217b6637646a3c49 (diff) |
Let's sprinkle some FastJNI into Resources.
Before:
benchmark us linear runtime
GetColor 14.9 ===========
GetInteger 19.9 ===============
GetLayoutAndTraverse 38.4 =============================
GetString 38.5 ==============================
After:
benchmark us linear runtime
GetColor 13.9 ==========
GetInteger 18.8 ==============
GetLayoutAndTraverse 38.1 =============================
GetString 38.2 ==============================
Change-Id: I8c20e14182d2645bc62a0e7fc6345e298b11933c
Diffstat (limited to 'core/tests/benchmarks')
-rw-r--r-- | core/tests/benchmarks/src/android/content/res/ResourcesBenchmark.java | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/core/tests/benchmarks/src/android/content/res/ResourcesBenchmark.java b/core/tests/benchmarks/src/android/content/res/ResourcesBenchmark.java new file mode 100644 index 000000000000..3638473aac03 --- /dev/null +++ b/core/tests/benchmarks/src/android/content/res/ResourcesBenchmark.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2015 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.content.res; + +import android.util.AttributeSet; +import android.util.Xml; + +import com.android.internal.R; +import com.google.caliper.SimpleBenchmark; + +import org.xmlpull.v1.XmlPullParser; + +public class ResourcesBenchmark extends SimpleBenchmark { + + private AssetManager mAsset; + private Resources mRes; + + private int mTextId; + private int mColorId; + private int mIntegerId; + private int mLayoutId; + + @Override + protected void setUp() { + mAsset = new AssetManager(); + mAsset.addAssetPath("/system/framework/framework-res.apk"); + mRes = new Resources(mAsset, null, null); + + mTextId = mRes.getIdentifier("cancel", "string", "android"); + mColorId = mRes.getIdentifier("transparent", "color", "android"); + mIntegerId = mRes.getIdentifier("config_shortAnimTime", "integer", "android"); + mLayoutId = mRes.getIdentifier("two_line_list_item", "layout", "android"); + } + + @Override + protected void tearDown() { + mAsset.close(); + } + + public void timeGetString(int reps) { + for (int i = 0; i < reps; i++) { + mRes.getText(mTextId); + } + } + + public void timeGetColor(int reps) { + for (int i = 0; i < reps; i++) { + mRes.getColor(mColorId, null); + } + } + + public void timeGetInteger(int reps) { + for (int i = 0; i < reps; i++) { + mRes.getInteger(mIntegerId); + } + } + + public void timeGetLayoutAndTraverse(int reps) throws Exception { + for (int i = 0; i < reps; i++) { + final XmlResourceParser parser = mRes.getLayout(mLayoutId); + try { + while (parser.next() != XmlPullParser.END_DOCUMENT) { + // Walk the entire tree + } + } finally { + parser.close(); + } + } + } +} |