|
| 1 | +// Copyright 2018, OpenCensus Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#include "opencensus/tags/tag_map.h" |
| 16 | + |
| 17 | +#include <utility> |
| 18 | +#include <vector> |
| 19 | + |
| 20 | +#include "absl/strings/str_cat.h" |
| 21 | +#include "benchmark/benchmark.h" |
| 22 | +#include "opencensus/tags/tag_key.h" |
| 23 | + |
| 24 | +namespace opencensus { |
| 25 | +namespace tags { |
| 26 | +namespace { |
| 27 | + |
| 28 | +void BM_MakeTagMap(benchmark::State& state) { |
| 29 | + // Create a vector with N tags. |
| 30 | + const int n = state.range(0); |
| 31 | + std::vector<std::pair<TagKey, std::string>> tags; |
| 32 | + tags.reserve(n); |
| 33 | + for (int i = 0; i < n; ++i) { |
| 34 | + tags.emplace_back(TagKey::Register(absl::StrCat("key", i)), |
| 35 | + absl::StrCat("val", i)); |
| 36 | + } |
| 37 | + // Benchmark TagMap initialization. |
| 38 | + for (auto _ : state) { |
| 39 | + TagMap tm(tags); |
| 40 | + } |
| 41 | +} |
| 42 | +BENCHMARK(BM_MakeTagMap)->RangeMultiplier(2)->Range(1, 32); |
| 43 | + |
| 44 | +} // namespace |
| 45 | +} // namespace tags |
| 46 | +} // namespace opencensus |
| 47 | + |
| 48 | +BENCHMARK_MAIN(); |
0 commit comments