Skip to content

benchmark missing UseManualTime #688

@czln

Description

@czln

in function BM_Histogram_Observe and some others, they use SetIterationTime to set the time cost manually, but did not call function UseManualTime, which means, the manual time cost won't print.

static void BM_Histogram_Observe(benchmark::State& state) {
  using prometheus::BuildHistogram;
  using prometheus::Histogram;
  using prometheus::Registry;

  const auto number_of_buckets = state.range(0);

  Registry registry;
  auto& histogram_family =
      BuildHistogram().Name("benchmark_histogram").Help("").Register(registry);
  auto bucket_boundaries = CreateLinearBuckets(0, number_of_buckets - 1, 1);
  auto& histogram = histogram_family.Add({}, bucket_boundaries);
  std::random_device rd;
  std::mt19937 gen(rd());
  std::uniform_real_distribution<> d(0, number_of_buckets);

  while (state.KeepRunning()) {
    auto observation = d(gen);
    auto start = std::chrono::high_resolution_clock::now();
    histogram.Observe(observation);
    auto end = std::chrono::high_resolution_clock::now();

    auto elapsed_seconds =
        std::chrono::duration_cast<std::chrono::duration<double>>(end - start);
    state.SetIterationTime(elapsed_seconds.count());
  }
}
BENCHMARK(BM_Histogram_Observe)->Range(0, 4096)->UseManualTime(); // here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions