Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
google_bb_bench.hpp
Go to the documentation of this file.
1// integrates bb bench stats with google benchmark
2#pragma once
3#include <benchmark/benchmark.h>
4
5#ifdef __wasm__
6namespace bb {
7struct GoogleBbBenchReporter {
8 GoogleBbBenchReporter(::benchmark::State& state)
9 {
10 // unused, we don't have op counts on
11 (void)state;
12 }
13};
14}; // namespace bb
15// require a semicolon to appease formatters
16#define GOOGLE_BB_BENCH_REPORTER(state) (void)0
17#define GOOGLE_BB_BENCH_REPORTER_CANCEL() (void)0
18#else
19#include "bb_bench.hpp"
20namespace bb {
21// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions)
23 // We allow having a ref member as this only lives inside a function frame
24 ::benchmark::State& state;
25 bool cancelled = false;
26 GoogleBbBenchReporter(::benchmark::State& state)
27 : state(state)
28 {
30 // Intent: Clear when we enter the state loop
32 }
34 {
35 if (std::getenv("BB_BENCH") != nullptr) {
37 }
38 // Allow for conditional reporting
39 if (cancelled) {
40 return;
41 }
42 // Intent: Collect results when we exit the state loop
43 for (auto& [key, parent_map] : bb::detail::GLOBAL_BENCH_STATS.aggregate()) {
44 for (auto& entry : parent_map) {
45 state.counters[std::string(key) + "(s)"] += static_cast<double>(entry.second.time);
46 state.counters[std::string(key)] += static_cast<double>(entry.second.count);
47 }
48 }
49 }
50};
51// Allow for integration with google benchmark user-defined counters
52// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
53#define GOOGLE_BB_BENCH_REPORTER(state) bb::GoogleBbBenchReporter __GOOGLE_BB_BENCH_REPORTER{ state };
54// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
55#define GOOGLE_BB_BENCH_REPORTER_CANCEL() __GOOGLE_BB_BENCH_REPORTER.cancelled = true;
56}; // namespace bb
57#endif
GlobalBenchStatsContainer GLOBAL_BENCH_STATS
Definition bb_bench.cpp:569
bool use_bb_bench
Definition bb_bench.cpp:172
Entry point for Barretenberg command-line interface.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
GoogleBbBenchReporter(::benchmark::State &state)
::benchmark::State & state
void print_aggregate_counts_hierarchical(std::ostream &) const
Definition bb_bench.cpp:299