Skip to content

Commit

Permalink
break apart tracked vs untracked registry
Browse files Browse the repository at this point in the history
  • Loading branch information
tobz committed May 19, 2021
1 parent 5dbe21f commit c4a86db
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
2 changes: 1 addition & 1 deletion metrics-benchmark/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use getopts::Options;
use hdrhistogram::Histogram;
use log::{error, info};
use metrics::{gauge, histogram, increment_counter, GaugeValue, Key, Recorder, Unit};
use metrics_util::{Handle, MetricKind, Registry, Tracked};
use metrics_util::{Handle, MetricKind, NotTracked, Registry, Tracked};
use quanta::{Clock, Instant as QuantaInstant};
use std::{
env,
Expand Down
53 changes: 51 additions & 2 deletions metrics-util/benches/registry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
use metrics::{Key, Label};
use metrics_util::{MetricKind, NotTracked, Registry};
use metrics_util::{MetricKind, NotTracked, Registry, Tracked};

fn registry_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("registry (not tracked)");
Expand Down Expand Up @@ -40,13 +40,62 @@ fn registry_benchmark(c: &mut Criterion) {
BatchSize::SmallInput,
)
});
group.bench_function("registry overhead", |b| {
group.bench_function("creation overhead", |b| {
b.iter_batched(
|| (),
|_| Registry::<Key, (), NotTracked<()>>::untracked(),
BatchSize::NumIterations(1),
)
});
group.finish();

let mut group = c.benchmark_group("registry (tracked)");
group.bench_function("cached op (basic)", |b| {
let registry = Registry::<Key, (), Tracked<()>>::tracked();
static KEY_NAME: &'static str = "simple_key";
static KEY_DATA: Key = Key::from_static_name(&KEY_NAME);

b.iter(|| registry.op(MetricKind::Counter, &KEY_DATA, |_| (), || ()))
});
group.bench_function("cached op (labels)", |b| {
let registry = Registry::<Key, (), Tracked<()>>::tracked();
static KEY_NAME: &'static str = "simple_key";
static KEY_LABELS: [Label; 1] = [Label::from_static_parts("type", "http")];
static KEY_DATA: Key = Key::from_static_parts(&KEY_NAME, &KEY_LABELS);

b.iter(|| registry.op(MetricKind::Counter, &KEY_DATA, |_| (), || ()))
});
group.bench_function("uncached op (basic)", |b| {
b.iter_batched_ref(
|| Registry::<Key, (), Tracked<()>>::tracked(),
|registry| {
let key = "simple_key".into();
registry.op(MetricKind::Counter, &key, |_| (), || ())
},
BatchSize::SmallInput,
)
});
group.bench_function("uncached op (labels)", |b| {
b.iter_batched_ref(
|| Registry::<Key, (), NotTracked<()>>::tracked(),
|registry| {
let labels = vec![Label::new("type", "http")];
let key = ("simple_key", labels).into();
registry.op(MetricKind::Counter, &key, |_| (), || ())
},
BatchSize::SmallInput,
)
});
group.bench_function("creation overhead", |b| {
b.iter_batched(
|| (),
|_| Registry::<Key, (), Tracked<()>>::tracked(),
BatchSize::NumIterations(1),
)
});
group.finish();

let mut group = c.benchmark_group("registry (common)");
group.bench_function("const key overhead (basic)", |b| {
b.iter(|| {
static KEY_NAME: &'static str = "simple_key";
Expand Down

0 comments on commit c4a86db

Please sign in to comment.