Skip to content

Commit 987037c

Browse files
authored
benches: add baseline cases (#185)
Signed-off-by: MOZGIII <[email protected]>
1 parent 23c31bd commit 987037c

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

Diff for: Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ hyper = { version = "0.14.16", features = ["server", "http1", "tcp"] }
4040
[build-dependencies]
4141
prost-build = { version = "0.11.0", optional = true }
4242

43+
[[bench]]
44+
name = "baseline"
45+
harness = false
46+
4347
[[bench]]
4448
name = "family"
4549
harness = false
@@ -54,4 +58,4 @@ required-features = []
5458
name = "proto"
5559
path = "benches/encoding/proto.rs"
5660
harness = false
57-
required-features = ["protobuf"]
61+
required-features = ["protobuf"]

Diff for: benches/baseline.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use criterion::{criterion_group, criterion_main, Criterion};
2+
use prometheus_client::metrics::counter::Counter;
3+
use prometheus_client::metrics::family::Family;
4+
5+
pub fn baseline(c: &mut Criterion) {
6+
c.bench_function("counter", |b| {
7+
let counter: Counter = Counter::default();
8+
9+
b.iter(|| {
10+
counter.inc();
11+
})
12+
});
13+
14+
c.bench_function("counter via family lookup", |b| {
15+
let family = Family::<(), Counter>::default();
16+
17+
b.iter(|| {
18+
family.get_or_create(&()).inc();
19+
})
20+
});
21+
}
22+
23+
criterion_group!(benches, baseline);
24+
criterion_main!(benches);

Diff for: benches/family.rs

+26
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,32 @@ use prometheus_client::metrics::counter::Counter;
33
use prometheus_client::metrics::family::Family;
44

55
pub fn family(c: &mut Criterion) {
6+
c.bench_function(
7+
"counter family with [(&'static str, &'static str)] label set",
8+
|b| {
9+
let family = Family::<[(&'static str, &'static str); 2], Counter>::default();
10+
11+
b.iter(|| {
12+
family
13+
.get_or_create(&[("method", "GET"), ("status", "200")])
14+
.inc();
15+
})
16+
},
17+
);
18+
19+
c.bench_function(
20+
"counter family with Vec<(&'static str, &'static str)> label set",
21+
|b| {
22+
let family = Family::<Vec<(&'static str, &'static str)>, Counter>::default();
23+
24+
b.iter(|| {
25+
family
26+
.get_or_create(&vec![("method", "GET"), ("status", "200")])
27+
.inc();
28+
})
29+
},
30+
);
31+
632
c.bench_function("counter family with Vec<(String, String)> label set", |b| {
733
let family = Family::<Vec<(String, String)>, Counter>::default();
834

0 commit comments

Comments
 (0)