random_benchmark.cc 649 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. #include <benchmark/benchmark.h>
  4. #include <random>
  5. #include "src/common/random.h"
  6. namespace
  7. {
  8. using opentelemetry::sdk::common::Random;
  9. void BM_RandomIdGeneration(benchmark::State &state)
  10. {
  11. while (state.KeepRunning())
  12. {
  13. benchmark::DoNotOptimize(Random::GenerateRandom64());
  14. }
  15. }
  16. BENCHMARK(BM_RandomIdGeneration);
  17. void BM_RandomIdStdGeneration(benchmark::State &state)
  18. {
  19. std::mt19937_64 generator{0};
  20. while (state.KeepRunning())
  21. {
  22. benchmark::DoNotOptimize(generator());
  23. }
  24. }
  25. BENCHMARK(BM_RandomIdStdGeneration);
  26. } // namespace
  27. BENCHMARK_MAIN();