blob: fffeeb802873d32649730f72dc1025ba7f72707e [file] [log] [blame]
Adam Lesinskic8f71aa2017-02-08 07:03:50 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "androidfw/AssetManager.h"
18#include "androidfw/ResourceTypes.h"
Brandon Liu742b11e2022-11-03 23:23:28 +000019#include "android-base/file.h"
Adam Lesinskic8f71aa2017-02-08 07:03:50 -080020
21#include "BenchmarkHelpers.h"
Adam Lesinskic8f71aa2017-02-08 07:03:50 -080022#include "data/sparse/R.h"
23
24namespace sparse = com::android::sparse;
25
26namespace android {
27
Brandon Liu742b11e2022-11-03 23:23:28 +000028static void BM_SparseEntryGetResourceHelper(const std::vector<std::string>& paths,
29 uint32_t resid, benchmark::State& state, void (*GetResourceBenchmarkFunc)(
30 const std::vector<std::string>&, const ResTable_config*,
31 uint32_t, benchmark::State&)){
32 ResTable_config config;
33 memset(&config, 0, sizeof(config));
34 config.orientation = ResTable_config::ORIENTATION_LAND;
35 GetResourceBenchmarkFunc(paths, &config, resid, state);
36}
37
Adam Lesinski73f6f9d2017-11-14 10:18:05 -080038static void BM_SparseEntryGetResourceOldSparse(benchmark::State& state, uint32_t resid) {
Brandon Liu742b11e2022-11-03 23:23:28 +000039 BM_SparseEntryGetResourceHelper({GetTestDataPath() + "/sparse/sparse.apk"}, resid,
40 state, &GetResourceBenchmarkOld);
Adam Lesinskic8f71aa2017-02-08 07:03:50 -080041}
Adam Lesinski73f6f9d2017-11-14 10:18:05 -080042BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldSparse, Small, sparse::R::integer::foo_9);
43BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldSparse, Large, sparse::R::string::foo_999);
Adam Lesinskic8f71aa2017-02-08 07:03:50 -080044
Adam Lesinski73f6f9d2017-11-14 10:18:05 -080045static void BM_SparseEntryGetResourceOldNotSparse(benchmark::State& state, uint32_t resid) {
Brandon Liu742b11e2022-11-03 23:23:28 +000046 BM_SparseEntryGetResourceHelper({GetTestDataPath() + "/sparse/not_sparse.apk"}, resid,
47 state, &GetResourceBenchmarkOld);
Adam Lesinskic8f71aa2017-02-08 07:03:50 -080048}
Adam Lesinski73f6f9d2017-11-14 10:18:05 -080049BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldNotSparse, Small, sparse::R::integer::foo_9);
50BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldNotSparse, Large, sparse::R::string::foo_999);
Adam Lesinskic8f71aa2017-02-08 07:03:50 -080051
Adam Lesinski73f6f9d2017-11-14 10:18:05 -080052static void BM_SparseEntryGetResourceSparse(benchmark::State& state, uint32_t resid) {
Brandon Liu742b11e2022-11-03 23:23:28 +000053 BM_SparseEntryGetResourceHelper({GetTestDataPath() + "/sparse/sparse.apk"}, resid,
54 state, &GetResourceBenchmark);
Adam Lesinskic8f71aa2017-02-08 07:03:50 -080055}
Adam Lesinski73f6f9d2017-11-14 10:18:05 -080056BENCHMARK_CAPTURE(BM_SparseEntryGetResourceSparse, Small, sparse::R::integer::foo_9);
57BENCHMARK_CAPTURE(BM_SparseEntryGetResourceSparse, Large, sparse::R::string::foo_999);
Adam Lesinskic8f71aa2017-02-08 07:03:50 -080058
Adam Lesinski73f6f9d2017-11-14 10:18:05 -080059static void BM_SparseEntryGetResourceNotSparse(benchmark::State& state, uint32_t resid) {
Brandon Liu742b11e2022-11-03 23:23:28 +000060 BM_SparseEntryGetResourceHelper({GetTestDataPath() + "/sparse/not_sparse.apk"}, resid,
61 state, &GetResourceBenchmark);
Adam Lesinskic8f71aa2017-02-08 07:03:50 -080062}
Adam Lesinski73f6f9d2017-11-14 10:18:05 -080063BENCHMARK_CAPTURE(BM_SparseEntryGetResourceNotSparse, Small, sparse::R::integer::foo_9);
64BENCHMARK_CAPTURE(BM_SparseEntryGetResourceNotSparse, Large, sparse::R::string::foo_999);
Adam Lesinskic8f71aa2017-02-08 07:03:50 -080065
Brandon Liu742b11e2022-11-03 23:23:28 +000066static void BM_SparseEntryGetResourceOldSparseRuntime(benchmark::State& state, uint32_t resid) {
67 BM_SparseEntryGetResourceHelper({base::GetExecutableDirectory() +
68 "/FrameworkResourcesSparseTestApp.apk"}, resid, state,
69 &GetResourceBenchmarkOld);
70}
71BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldSparseRuntime, Small, sparse::R::integer::foo_9);
72BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldSparseRuntime, Large, sparse::R::string::foo_999);
73
74static void BM_SparseEntryGetResourceOldNotSparseRuntime(benchmark::State& state, uint32_t resid) {
75 BM_SparseEntryGetResourceHelper({base::GetExecutableDirectory() +
76 "/FrameworkResourcesNotSparseTestApp.apk"}, resid, state,
77 &GetResourceBenchmarkOld);
78}
79BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldNotSparseRuntime, Small, sparse::R::integer::foo_9);
80BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldNotSparseRuntime, Large, sparse::R::string::foo_999);
81
82static void BM_SparseEntryGetResourceSparseRuntime(benchmark::State& state, uint32_t resid) {
83 BM_SparseEntryGetResourceHelper({base::GetExecutableDirectory() +
84 "/FrameworkResourcesSparseTestApp.apk"}, resid, state,
85 &GetResourceBenchmark);
86}
87BENCHMARK_CAPTURE(BM_SparseEntryGetResourceSparseRuntime, Small, sparse::R::integer::foo_9);
88BENCHMARK_CAPTURE(BM_SparseEntryGetResourceSparseRuntime, Large, sparse::R::string::foo_999);
89
90static void BM_SparseEntryGetResourceNotSparseRuntime(benchmark::State& state, uint32_t resid) {
91 BM_SparseEntryGetResourceHelper({base::GetExecutableDirectory() +
92 "/FrameworkResourcesNotSparseTestApp.apk"}, resid, state,
93 &GetResourceBenchmark);
94}
95BENCHMARK_CAPTURE(BM_SparseEntryGetResourceNotSparseRuntime, Small, sparse::R::integer::foo_9);
96BENCHMARK_CAPTURE(BM_SparseEntryGetResourceNotSparseRuntime, Large, sparse::R::string::foo_999);
97
Adam Lesinskic8f71aa2017-02-08 07:03:50 -080098} // namespace android