From ff7642195b91f5e547d7bbf5802842f6d1aee655 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Sat, 30 Aug 2025 17:59:24 -0400 Subject: [PATCH] Make benchmark metric families global --- benchmarks/bench_metric.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/benchmarks/bench_metric.cpp b/benchmarks/bench_metric.cpp index 4fae4be..e829730 100644 --- a/benchmarks/bench_metric.cpp +++ b/benchmarks/bench_metric.cpp @@ -10,6 +10,12 @@ #include #include +metric::Family gauge_family = metric::create_gauge("gauge", ""); +metric::Family counter_family = + metric::create_counter("counter", ""); +metric::Family histogram_family = metric::create_histogram( + "histogram", "", metric::exponential_buckets(0.001, 5, 8)); + // High-contention benchmark setup struct ContentionEnvironment { // Background threads for contention @@ -20,13 +26,6 @@ struct ContentionEnvironment { std::unique_ptr contention_latch; std::unique_ptr render_latch; - metric::Family gauge_family = - metric::create_gauge("gauge", ""); - metric::Family counter_family = - metric::create_counter("counter", ""); - metric::Family histogram_family = metric::create_histogram( - "histogram", "", metric::exponential_buckets(0.001, 5, 8)); - ContentionEnvironment() = default; void start_background_contention(int num_threads = 4) { @@ -94,13 +93,6 @@ int main() { ankerl::nanobench::Bench bench; bench.title("WeaselDB Metrics Performance").unit("operation").warmup(1000); - metric::Family gauge_family = - metric::create_gauge("gauge", ""); - metric::Family counter_family = - metric::create_counter("counter", ""); - metric::Family histogram_family = metric::create_histogram( - "histogram", "", metric::exponential_buckets(0.001, 5, 8)); - auto counter = counter_family.create({}); auto gauge = gauge_family.create({}); auto histogram = histogram_family.create({});