attributes_processor_benchmark.cc 895 B

123456789101112131415161718192021222324252627282930
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. #include <benchmark/benchmark.h>
  4. #include <map>
  5. #include <string>
  6. #include "opentelemetry/common/key_value_iterable_view.h"
  7. #include "opentelemetry/sdk/metrics/view/attributes_processor.h"
  8. using namespace opentelemetry::sdk::metrics;
  9. namespace
  10. {
  11. void BM_AttributseProcessorFilter(benchmark::State &state)
  12. {
  13. std::map<std::string, int> attributes = {
  14. {"att1", 10}, {"attr1", 20}, {"attr3", 30}, {"attr4", 40}};
  15. FilteringAttributesProcessor attributes_processor(
  16. {{"attr2", true}, {"attr4", true}, {"attr6", true}});
  17. opentelemetry::common::KeyValueIterableView<std::map<std::string, int>> iterable(attributes);
  18. while (state.KeepRunning())
  19. {
  20. auto filtered_attributes = attributes_processor.process(iterable);
  21. }
  22. }
  23. BENCHMARK(BM_AttributseProcessorFilter);
  24. } // namespace
  25. BENCHMARK_MAIN();