1 /* 2 * Copyright (C) 2020 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 "benchmark/benchmark.h" 18 19 #include "androidfw/CursorWindow.h" 20 21 namespace android { 22 23 static void BM_CursorWindowWrite(benchmark::State& state, size_t rows, size_t cols) { 24 CursorWindow* w; 25 CursorWindow::create(String8("test"), 1 << 21, &w); 26 27 while (state.KeepRunning()) { 28 w->clear(); 29 w->setNumColumns(cols); 30 for (int row = 0; row < rows; row++) { 31 w->allocRow(); 32 for (int col = 0; col < cols; col++) { 33 w->putLong(row, col, 0xcafe); 34 } 35 } 36 } 37 } 38 39 static void BM_CursorWindowWrite4x4(benchmark::State& state) { 40 BM_CursorWindowWrite(state, 4, 4); 41 } 42 BENCHMARK(BM_CursorWindowWrite4x4); 43 44 static void BM_CursorWindowWrite1Kx4(benchmark::State& state) { 45 BM_CursorWindowWrite(state, 1024, 4); 46 } 47 BENCHMARK(BM_CursorWindowWrite1Kx4); 48 49 static void BM_CursorWindowWrite16Kx4(benchmark::State& state) { 50 BM_CursorWindowWrite(state, 16384, 4); 51 } 52 BENCHMARK(BM_CursorWindowWrite16Kx4); 53 54 static void BM_CursorWindowRead(benchmark::State& state, size_t rows, size_t cols) { 55 CursorWindow* w; 56 CursorWindow::create(String8("test"), 1 << 21, &w); 57 w->setNumColumns(cols); 58 for (int row = 0; row < rows; row++) { 59 w->allocRow(); 60 } 61 62 while (state.KeepRunning()) { 63 for (int row = 0; row < rows; row++) { 64 for (int col = 0; col < cols; col++) { 65 w->getFieldSlot(row, col); 66 } 67 } 68 } 69 } 70 71 static void BM_CursorWindowRead4x4(benchmark::State& state) { 72 BM_CursorWindowRead(state, 4, 4); 73 } 74 BENCHMARK(BM_CursorWindowRead4x4); 75 76 static void BM_CursorWindowRead1Kx4(benchmark::State& state) { 77 BM_CursorWindowRead(state, 1024, 4); 78 } 79 BENCHMARK(BM_CursorWindowRead1Kx4); 80 81 static void BM_CursorWindowRead16Kx4(benchmark::State& state) { 82 BM_CursorWindowRead(state, 16384, 4); 83 } 84 BENCHMARK(BM_CursorWindowRead16Kx4); 85 86 } // namespace android 87