Adam Lesinski | c8f71aa | 2017-02-08 07:03:50 -0800 | [diff] [blame] | 1 | /* |
| 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 Liu | 742b11e | 2022-11-03 23:23:28 +0000 | [diff] [blame] | 19 | #include "android-base/file.h" |
Adam Lesinski | c8f71aa | 2017-02-08 07:03:50 -0800 | [diff] [blame] | 20 | |
| 21 | #include "BenchmarkHelpers.h" |
Adam Lesinski | c8f71aa | 2017-02-08 07:03:50 -0800 | [diff] [blame] | 22 | #include "data/sparse/R.h" |
| 23 | |
| 24 | namespace sparse = com::android::sparse; |
| 25 | |
| 26 | namespace android { |
| 27 | |
Brandon Liu | 742b11e | 2022-11-03 23:23:28 +0000 | [diff] [blame] | 28 | static 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 Lesinski | 73f6f9d | 2017-11-14 10:18:05 -0800 | [diff] [blame] | 38 | static void BM_SparseEntryGetResourceOldSparse(benchmark::State& state, uint32_t resid) { |
Brandon Liu | 742b11e | 2022-11-03 23:23:28 +0000 | [diff] [blame] | 39 | BM_SparseEntryGetResourceHelper({GetTestDataPath() + "/sparse/sparse.apk"}, resid, |
| 40 | state, &GetResourceBenchmarkOld); |
Adam Lesinski | c8f71aa | 2017-02-08 07:03:50 -0800 | [diff] [blame] | 41 | } |
Adam Lesinski | 73f6f9d | 2017-11-14 10:18:05 -0800 | [diff] [blame] | 42 | BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldSparse, Small, sparse::R::integer::foo_9); |
| 43 | BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldSparse, Large, sparse::R::string::foo_999); |
Adam Lesinski | c8f71aa | 2017-02-08 07:03:50 -0800 | [diff] [blame] | 44 | |
Adam Lesinski | 73f6f9d | 2017-11-14 10:18:05 -0800 | [diff] [blame] | 45 | static void BM_SparseEntryGetResourceOldNotSparse(benchmark::State& state, uint32_t resid) { |
Brandon Liu | 742b11e | 2022-11-03 23:23:28 +0000 | [diff] [blame] | 46 | BM_SparseEntryGetResourceHelper({GetTestDataPath() + "/sparse/not_sparse.apk"}, resid, |
| 47 | state, &GetResourceBenchmarkOld); |
Adam Lesinski | c8f71aa | 2017-02-08 07:03:50 -0800 | [diff] [blame] | 48 | } |
Adam Lesinski | 73f6f9d | 2017-11-14 10:18:05 -0800 | [diff] [blame] | 49 | BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldNotSparse, Small, sparse::R::integer::foo_9); |
| 50 | BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldNotSparse, Large, sparse::R::string::foo_999); |
Adam Lesinski | c8f71aa | 2017-02-08 07:03:50 -0800 | [diff] [blame] | 51 | |
Adam Lesinski | 73f6f9d | 2017-11-14 10:18:05 -0800 | [diff] [blame] | 52 | static void BM_SparseEntryGetResourceSparse(benchmark::State& state, uint32_t resid) { |
Brandon Liu | 742b11e | 2022-11-03 23:23:28 +0000 | [diff] [blame] | 53 | BM_SparseEntryGetResourceHelper({GetTestDataPath() + "/sparse/sparse.apk"}, resid, |
| 54 | state, &GetResourceBenchmark); |
Adam Lesinski | c8f71aa | 2017-02-08 07:03:50 -0800 | [diff] [blame] | 55 | } |
Adam Lesinski | 73f6f9d | 2017-11-14 10:18:05 -0800 | [diff] [blame] | 56 | BENCHMARK_CAPTURE(BM_SparseEntryGetResourceSparse, Small, sparse::R::integer::foo_9); |
| 57 | BENCHMARK_CAPTURE(BM_SparseEntryGetResourceSparse, Large, sparse::R::string::foo_999); |
Adam Lesinski | c8f71aa | 2017-02-08 07:03:50 -0800 | [diff] [blame] | 58 | |
Adam Lesinski | 73f6f9d | 2017-11-14 10:18:05 -0800 | [diff] [blame] | 59 | static void BM_SparseEntryGetResourceNotSparse(benchmark::State& state, uint32_t resid) { |
Brandon Liu | 742b11e | 2022-11-03 23:23:28 +0000 | [diff] [blame] | 60 | BM_SparseEntryGetResourceHelper({GetTestDataPath() + "/sparse/not_sparse.apk"}, resid, |
| 61 | state, &GetResourceBenchmark); |
Adam Lesinski | c8f71aa | 2017-02-08 07:03:50 -0800 | [diff] [blame] | 62 | } |
Adam Lesinski | 73f6f9d | 2017-11-14 10:18:05 -0800 | [diff] [blame] | 63 | BENCHMARK_CAPTURE(BM_SparseEntryGetResourceNotSparse, Small, sparse::R::integer::foo_9); |
| 64 | BENCHMARK_CAPTURE(BM_SparseEntryGetResourceNotSparse, Large, sparse::R::string::foo_999); |
Adam Lesinski | c8f71aa | 2017-02-08 07:03:50 -0800 | [diff] [blame] | 65 | |
Brandon Liu | 742b11e | 2022-11-03 23:23:28 +0000 | [diff] [blame] | 66 | static void BM_SparseEntryGetResourceOldSparseRuntime(benchmark::State& state, uint32_t resid) { |
| 67 | BM_SparseEntryGetResourceHelper({base::GetExecutableDirectory() + |
| 68 | "/FrameworkResourcesSparseTestApp.apk"}, resid, state, |
| 69 | &GetResourceBenchmarkOld); |
| 70 | } |
| 71 | BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldSparseRuntime, Small, sparse::R::integer::foo_9); |
| 72 | BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldSparseRuntime, Large, sparse::R::string::foo_999); |
| 73 | |
| 74 | static void BM_SparseEntryGetResourceOldNotSparseRuntime(benchmark::State& state, uint32_t resid) { |
| 75 | BM_SparseEntryGetResourceHelper({base::GetExecutableDirectory() + |
| 76 | "/FrameworkResourcesNotSparseTestApp.apk"}, resid, state, |
| 77 | &GetResourceBenchmarkOld); |
| 78 | } |
| 79 | BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldNotSparseRuntime, Small, sparse::R::integer::foo_9); |
| 80 | BENCHMARK_CAPTURE(BM_SparseEntryGetResourceOldNotSparseRuntime, Large, sparse::R::string::foo_999); |
| 81 | |
| 82 | static void BM_SparseEntryGetResourceSparseRuntime(benchmark::State& state, uint32_t resid) { |
| 83 | BM_SparseEntryGetResourceHelper({base::GetExecutableDirectory() + |
| 84 | "/FrameworkResourcesSparseTestApp.apk"}, resid, state, |
| 85 | &GetResourceBenchmark); |
| 86 | } |
| 87 | BENCHMARK_CAPTURE(BM_SparseEntryGetResourceSparseRuntime, Small, sparse::R::integer::foo_9); |
| 88 | BENCHMARK_CAPTURE(BM_SparseEntryGetResourceSparseRuntime, Large, sparse::R::string::foo_999); |
| 89 | |
| 90 | static void BM_SparseEntryGetResourceNotSparseRuntime(benchmark::State& state, uint32_t resid) { |
| 91 | BM_SparseEntryGetResourceHelper({base::GetExecutableDirectory() + |
| 92 | "/FrameworkResourcesNotSparseTestApp.apk"}, resid, state, |
| 93 | &GetResourceBenchmark); |
| 94 | } |
| 95 | BENCHMARK_CAPTURE(BM_SparseEntryGetResourceNotSparseRuntime, Small, sparse::R::integer::foo_9); |
| 96 | BENCHMARK_CAPTURE(BM_SparseEntryGetResourceNotSparseRuntime, Large, sparse::R::string::foo_999); |
| 97 | |
Adam Lesinski | c8f71aa | 2017-02-08 07:03:50 -0800 | [diff] [blame] | 98 | } // namespace android |