File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,10 @@ prost-build = { version = "0.12.0", optional = true }
4848name = " baseline"
4949harness = false
5050
51+ [[bench ]]
52+ name = " exemplars"
53+ harness = false
54+
5155[[bench ]]
5256name = " family"
5357harness = false
Original file line number Diff line number Diff line change 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) ;
You can’t perform that action at this time.
0 commit comments