forked from prometheus/client_rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexemplars.rs
More file actions
39 lines (29 loc) · 1.2 KB
/
exemplars.rs
File metadata and controls
39 lines (29 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use std::time::SystemTime;
use criterion::{criterion_group, criterion_main, Criterion};
use prometheus_client::metrics::exemplar::HistogramWithExemplars;
use prometheus_client::metrics::histogram::Histogram;
type Exemplar = Vec<(String, String)>;
const BUCKETS: &[f64] = &[1.0, 2.0, 3.0];
pub fn exemplars(c: &mut Criterion) {
c.bench_function("histogram without exemplars", |b| {
let histogram = Histogram::new(BUCKETS.iter().copied());
b.iter(|| {
histogram.observe(1.0);
});
});
c.bench_function("histogram with exemplars (no exemplar passed)", |b| {
let histogram = HistogramWithExemplars::<Exemplar>::new(BUCKETS.iter().copied());
b.iter(|| {
histogram.observe(1.0, None, None);
});
});
c.bench_function("histogram with exemplars (some exemplar passed)", |b| {
let histogram = HistogramWithExemplars::<Exemplar>::new(BUCKETS.iter().copied());
let exemplar = vec![("TraceID".to_owned(), "deadfeed".to_owned())];
b.iter(|| {
histogram.observe(1.0, Some(exemplar.clone()), Some(SystemTime::now()));
});
});
}
criterion_group!(benches, exemplars);
criterion_main!(benches);