diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/jaegertracing/opentelemetry-cpp/sdk/test/metrics/attributes_hashmap_benchmark.cc | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/jaegertracing/opentelemetry-cpp/sdk/test/metrics/attributes_hashmap_benchmark.cc')
-rw-r--r-- | src/jaegertracing/opentelemetry-cpp/sdk/test/metrics/attributes_hashmap_benchmark.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/jaegertracing/opentelemetry-cpp/sdk/test/metrics/attributes_hashmap_benchmark.cc b/src/jaegertracing/opentelemetry-cpp/sdk/test/metrics/attributes_hashmap_benchmark.cc new file mode 100644 index 000000000..38d515a7e --- /dev/null +++ b/src/jaegertracing/opentelemetry-cpp/sdk/test/metrics/attributes_hashmap_benchmark.cc @@ -0,0 +1,53 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +#include <benchmark/benchmark.h> +#ifndef ENABLE_METRICS_PREVIEW +# include "opentelemetry/sdk/common/attributemap_hash.h" +# include "opentelemetry/sdk/metrics/aggregation/aggregation.h" +# include "opentelemetry/sdk/metrics/aggregation/drop_aggregation.h" +# include "opentelemetry/sdk/metrics/instruments.h" +# include "opentelemetry/sdk/metrics/state/attributes_hashmap.h" + +# include <functional> +# include <vector> + +using namespace opentelemetry::sdk::metrics; +constexpr size_t MAX_THREADS = 500; +namespace +{ + +void BM_AttributseHashMap(benchmark::State &state) +{ + + AttributesHashMap hash_map; + std::vector<std::thread> workers; + std::vector<MetricAttributes> attributes = {{{"k1", "v1"}, {"k2", "v2"}}, + {{"k1", "v1"}, {"k2", "v2"}, {"k3", "v3"}}}; + + std::function<std::unique_ptr<Aggregation>()> create_default_aggregation = + []() -> std::unique_ptr<Aggregation> { + return std::unique_ptr<Aggregation>(new DropAggregation); + }; + + while (state.KeepRunning()) + { + for (size_t i = 0; i < MAX_THREADS; i++) + { + workers.push_back(std::thread([&]() { + hash_map.GetOrSetDefault(attributes[i % 2], create_default_aggregation)->Aggregate(1l); + benchmark::DoNotOptimize(hash_map.Has(attributes[i % 2])); + })); + } + } + + for (auto &t : workers) + { + t.join(); + } +} + +BENCHMARK(BM_AttributseHashMap); +} // namespace +#endif +BENCHMARK_MAIN();
\ No newline at end of file |