| /* | |
| * Copyright (C) 2026 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. | |
| */ | |
| #include <string> | |
| #include <vector> | |
| #include "android-base/file.h" | |
| #include "benchmark/benchmark.h" | |
| #include "util/Files.h" | |
| namespace aapt { | |
| static void BM_AppendArgsFromFile(benchmark::State& state) { | |
| std::string contents; | |
| contents.reserve(state.range(0) * 25); | |
| for (int i = 0; i < state.range(0); i++) { | |
| contents += "res/raw/file_"; | |
| contents += std::to_string(i); | |
| contents += ".xml\n"; | |
| } | |
| TemporaryFile tf; | |
| android::base::WriteStringToFd(contents, tf.fd); | |
| for (auto _ : state) { | |
| std::vector<std::string> out_arglist; | |
| std::string out_error; | |
| file::AppendArgsFromFile(tf.path, &out_arglist, &out_error); | |
| benchmark::DoNotOptimize(out_arglist); | |
| } | |
| } | |
| BENCHMARK(BM_AppendArgsFromFile)->RangeMultiplier(10)->Range(1, 100000); | |
| } // namespace aapt |