Skip to content

Commit f3351e2

Browse files
committed
add bench
1 parent b04d43f commit f3351e2

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ harness = false
6363
name = "family"
6464
harness = false
6565

66+
[[bench]]
67+
name = "histogram"
68+
harness = false
69+
6670
[[bench]]
6771
name = "text"
6872
path = "benches/encoding/text.rs"

benches/histogram.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2+
use prometheus_client::metrics::histogram::{exponential_buckets, Histogram};
3+
use prometheus_client::metrics::native_histogram::NativeHistogram;
4+
5+
const OBSERVATION: f64 = 64.0;
6+
7+
pub fn histogram(c: &mut Criterion) {
8+
let mut group = c.benchmark_group("observe");
9+
10+
group.bench_function("histogram", |b| {
11+
let histogram = Histogram::new(exponential_buckets(1.0, 2.0, 10));
12+
13+
b.iter(|| {
14+
histogram.observe(black_box(OBSERVATION));
15+
})
16+
});
17+
18+
group.bench_function("native histogram", |b| {
19+
let histogram = NativeHistogram::new(0);
20+
21+
b.iter(|| {
22+
histogram.observe(black_box(OBSERVATION));
23+
})
24+
});
25+
26+
group.finish();
27+
}
28+
29+
criterion_group!(benches, histogram);
30+
criterion_main!(benches);

0 commit comments

Comments
 (0)