Make benchmark metric families global

This commit is contained in:
2025-08-30 17:59:24 -04:00
parent 0ff197d406
commit ff7642195b

View File

@@ -10,6 +10,12 @@
#include <thread> #include <thread>
#include <vector> #include <vector>
metric::Family<metric::Gauge> gauge_family = metric::create_gauge("gauge", "");
metric::Family<metric::Counter> counter_family =
metric::create_counter("counter", "");
metric::Family<metric::Histogram> histogram_family = metric::create_histogram(
"histogram", "", metric::exponential_buckets(0.001, 5, 8));
// High-contention benchmark setup // High-contention benchmark setup
struct ContentionEnvironment { struct ContentionEnvironment {
// Background threads for contention // Background threads for contention
@@ -20,13 +26,6 @@ struct ContentionEnvironment {
std::unique_ptr<std::latch> contention_latch; std::unique_ptr<std::latch> contention_latch;
std::unique_ptr<std::latch> render_latch; std::unique_ptr<std::latch> render_latch;
metric::Family<metric::Gauge> gauge_family =
metric::create_gauge("gauge", "");
metric::Family<metric::Counter> counter_family =
metric::create_counter("counter", "");
metric::Family<metric::Histogram> histogram_family = metric::create_histogram(
"histogram", "", metric::exponential_buckets(0.001, 5, 8));
ContentionEnvironment() = default; ContentionEnvironment() = default;
void start_background_contention(int num_threads = 4) { void start_background_contention(int num_threads = 4) {
@@ -94,13 +93,6 @@ int main() {
ankerl::nanobench::Bench bench; ankerl::nanobench::Bench bench;
bench.title("WeaselDB Metrics Performance").unit("operation").warmup(1000); bench.title("WeaselDB Metrics Performance").unit("operation").warmup(1000);
metric::Family<metric::Gauge> gauge_family =
metric::create_gauge("gauge", "");
metric::Family<metric::Counter> counter_family =
metric::create_counter("counter", "");
metric::Family<metric::Histogram> histogram_family = metric::create_histogram(
"histogram", "", metric::exponential_buckets(0.001, 5, 8));
auto counter = counter_family.create({}); auto counter = counter_family.create({});
auto gauge = gauge_family.create({}); auto gauge = gauge_family.create({});
auto histogram = histogram_family.create({}); auto histogram = histogram_family.create({});