span_id_benchmark.cc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. #include <benchmark/benchmark.h>
  4. #include <cstdint>
  5. #include "opentelemetry/nostd/span.h"
  6. #include "opentelemetry/trace/span_id.h"
  7. namespace
  8. {
  9. using opentelemetry::trace::SpanId;
  10. constexpr uint8_t bytes[] = {1, 2, 3, 4, 5, 6, 7, 8};
  11. void BM_SpanIdDefaultConstructor(benchmark::State &state)
  12. {
  13. while (state.KeepRunning())
  14. {
  15. benchmark::DoNotOptimize(SpanId());
  16. }
  17. }
  18. BENCHMARK(BM_SpanIdDefaultConstructor);
  19. void BM_SpanIdConstructor(benchmark::State &state)
  20. {
  21. while (state.KeepRunning())
  22. {
  23. benchmark::DoNotOptimize(SpanId(bytes));
  24. }
  25. }
  26. BENCHMARK(BM_SpanIdConstructor);
  27. void BM_SpanIdToLowerBase16(benchmark::State &state)
  28. {
  29. SpanId id(bytes);
  30. char buf[SpanId::kSize * 2];
  31. while (state.KeepRunning())
  32. {
  33. id.ToLowerBase16(buf);
  34. benchmark::DoNotOptimize(buf);
  35. }
  36. }
  37. BENCHMARK(BM_SpanIdToLowerBase16);
  38. void BM_SpanIdIsValid(benchmark::State &state)
  39. {
  40. SpanId id(bytes);
  41. while (state.KeepRunning())
  42. {
  43. benchmark::DoNotOptimize(id.IsValid());
  44. }
  45. }
  46. BENCHMARK(BM_SpanIdIsValid);
  47. } // namespace
  48. BENCHMARK_MAIN();