Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark missing UseManualTime #688

Closed
czln opened this issue Jan 17, 2024 · 1 comment · Fixed by #691
Closed

benchmark missing UseManualTime #688

czln opened this issue Jan 17, 2024 · 1 comment · Fixed by #691

Comments

@czln
Copy link

czln commented Jan 17, 2024

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
@gjasny
Copy link
Collaborator

gjasny commented Jan 22, 2024

Thanks, good catch!

gjasny added a commit that referenced this issue Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants