Skip to content

Commit 7a37c3a

Browse files
committed
Add a benchmark for exemplars
1 parent cd3c3e8 commit 7a37c3a

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ prost-build = { version = "0.12.0", optional = true }
4848
name = "baseline"
4949
harness = false
5050

51+
[[bench]]
52+
name = "exemplars"
53+
harness = false
54+
5155
[[bench]]
5256
name = "family"
5357
harness = false

benches/exemplars.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use criterion::{criterion_group, criterion_main, Criterion};
2+
use prometheus_client::metrics::exemplar::HistogramWithExemplars;
3+
use prometheus_client::metrics::histogram::Histogram;
4+
5+
type Exemplar = Vec<(String, String)>;
6+
7+
const BUCKETS: &[f64] = &[1.0, 2.0, 3.0];
8+
9+
pub fn exemplars(c: &mut Criterion) {
10+
c.bench_function("histogram without exemplars", |b| {
11+
let histogram = Histogram::new(BUCKETS.into_iter().copied());
12+
13+
b.iter(|| {
14+
histogram.observe(1.0);
15+
});
16+
});
17+
18+
c.bench_function("histogram with exemplars (no exemplar passed)", |b| {
19+
let histogram = HistogramWithExemplars::<Exemplar>::new(BUCKETS.into_iter().copied());
20+
21+
b.iter(|| {
22+
histogram.observe(1.0, None);
23+
});
24+
});
25+
26+
c.bench_function("histogram with exemplars (some exemplar passed)", |b| {
27+
let histogram = HistogramWithExemplars::<Exemplar>::new(BUCKETS.into_iter().copied());
28+
let exemplar = vec![("TraceID".to_owned(), "deadfeed".to_owned())];
29+
30+
b.iter(|| {
31+
histogram.observe(1.0, Some(exemplar.clone()));
32+
});
33+
});
34+
}
35+
36+
criterion_group!(benches, exemplars);
37+
criterion_main!(benches);

0 commit comments

Comments
 (0)