Skip to content

Commit 430de6e

Browse files
authored
static-metric/benches: Use label_enum and get (#352)
* static-metric/benches: Use try_get instead of get > `fn get()` is only available when label is defined by `label_enum`. Signed-off-by: Max Inden <[email protected]> * static-metric/benches: Run rust fmt Signed-off-by: Max Inden <[email protected]> * static/metric/benches: Use label_enum for the two dimensions Signed-off-by: Max Inden <[email protected]>
1 parent 476862e commit 430de6e

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

static-metric/benches/benches.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.
22

33
#![feature(test)]
4-
#![feature(proc_macro)]
54

65
extern crate prometheus;
76
extern crate prometheus_static_metric;
@@ -52,13 +51,17 @@ fn bench_static_metrics_handwrite_2(b: &mut Bencher) {
5251
}
5352

5453
make_static_metric! {
54+
label_enum D1 {
55+
foo,
56+
}
57+
58+
label_enum D2 {
59+
bar,
60+
}
61+
5562
struct StaticCounter2: IntCounter {
56-
"d1" => {
57-
foo,
58-
},
59-
"d2" => {
60-
bar,
61-
},
63+
"d1" => D1,
64+
"d2" => D2,
6265
}
6366
}
6467

@@ -75,7 +78,7 @@ fn bench_static_metrics_macro(b: &mut Bencher) {
7578
fn bench_static_metrics_macro_with_lookup(b: &mut Bencher) {
7679
let counter_vec = IntCounterVec::new(Opts::new("foo", "bar"), &["d1", "d2"]).unwrap();
7780
let static_counter = StaticCounter2::from(&counter_vec);
78-
b.iter(|| static_counter.get("foo").get("bar").inc());
81+
b.iter(|| static_counter.get(D1::foo).get(D2::bar).inc());
7982
}
8083

8184
make_static_metric! {

0 commit comments

Comments
 (0)