Skip to content

Commit

Permalink
benches: add baseline cases (#185)
Browse files Browse the repository at this point in the history
Signed-off-by: MOZGIII <mike-n@narod.ru>
  • Loading branch information
MOZGIII committed Jan 26, 2024
1 parent 23c31bd commit 987037c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Cargo.toml
Expand Up @@ -40,6 +40,10 @@ hyper = { version = "0.14.16", features = ["server", "http1", "tcp"] }
[build-dependencies]
prost-build = { version = "0.11.0", optional = true }

[[bench]]
name = "baseline"
harness = false

[[bench]]
name = "family"
harness = false
Expand All @@ -54,4 +58,4 @@ required-features = []
name = "proto"
path = "benches/encoding/proto.rs"
harness = false
required-features = ["protobuf"]
required-features = ["protobuf"]
24 changes: 24 additions & 0 deletions benches/baseline.rs
@@ -0,0 +1,24 @@
use criterion::{criterion_group, criterion_main, Criterion};
use prometheus_client::metrics::counter::Counter;
use prometheus_client::metrics::family::Family;

pub fn baseline(c: &mut Criterion) {
c.bench_function("counter", |b| {
let counter: Counter = Counter::default();

b.iter(|| {
counter.inc();
})
});

c.bench_function("counter via family lookup", |b| {
let family = Family::<(), Counter>::default();

b.iter(|| {
family.get_or_create(&()).inc();
})
});
}

criterion_group!(benches, baseline);
criterion_main!(benches);
26 changes: 26 additions & 0 deletions benches/family.rs
Expand Up @@ -3,6 +3,32 @@ use prometheus_client::metrics::counter::Counter;
use prometheus_client::metrics::family::Family;

pub fn family(c: &mut Criterion) {
c.bench_function(
"counter family with [(&'static str, &'static str)] label set",
|b| {
let family = Family::<[(&'static str, &'static str); 2], Counter>::default();

b.iter(|| {
family
.get_or_create(&[("method", "GET"), ("status", "200")])
.inc();
})
},
);

c.bench_function(
"counter family with Vec<(&'static str, &'static str)> label set",
|b| {
let family = Family::<Vec<(&'static str, &'static str)>, Counter>::default();

b.iter(|| {
family
.get_or_create(&vec![("method", "GET"), ("status", "200")])
.inc();
})
},
);

c.bench_function("counter family with Vec<(String, String)> label set", |b| {
let family = Family::<Vec<(String, String)>, Counter>::default();

Expand Down

0 comments on commit 987037c

Please sign in to comment.