Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit e6a265f

Browse files
authored
Add tag_map_benchmark. (#245)
1 parent 8a81b1b commit e6a265f

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

opencensus/tags/BUILD

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ cc_test(
116116
# Benchmarks
117117
# ========================================================================= #
118118

119+
cc_binary(
120+
name = "tag_map_benchmark",
121+
testonly = 1,
122+
srcs = ["internal/tag_map_benchmark.cc"],
123+
copts = TEST_COPTS,
124+
linkstatic = 1,
125+
deps = [
126+
":tags",
127+
"@com_github_google_benchmark//:benchmark",
128+
"@com_google_absl//absl/strings",
129+
],
130+
)
131+
119132
cc_binary(
120133
name = "with_tag_map_benchmark",
121134
testonly = 1,
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
 (0)