@@ -32,13 +32,13 @@ thread_local! {
32
32
33
33
// Run this benchmark with:
34
34
// cargo bench --bench metric_counter
35
- fn create_counter ( ) -> Counter < u64 > {
35
+ fn create_counter ( name : & ' static str ) -> Counter < u64 > {
36
36
let meter_provider: SdkMeterProvider = SdkMeterProvider :: builder ( )
37
37
. with_reader ( ManualReader :: builder ( ) . build ( ) )
38
38
. build ( ) ;
39
39
let meter = meter_provider. meter ( "benchmarks" ) ;
40
40
41
- meter. u64_counter ( "counter_bench" ) . init ( )
41
+ meter. u64_counter ( name ) . init ( )
42
42
}
43
43
44
44
fn criterion_benchmark ( c : & mut Criterion ) {
@@ -51,8 +51,8 @@ fn counter_add(c: &mut Criterion) {
51
51
"value10" ,
52
52
] ;
53
53
54
- let counter = create_counter ( ) ;
55
54
c. bench_function ( "Counter_Add_Sorted" , |b| {
55
+ let counter = create_counter ( "Counter_Add_Sorted" ) ;
56
56
b. iter ( || {
57
57
// 4*4*10*10 = 1600 time series.
58
58
let rands = CURRENT_RNG . with ( |rng| {
@@ -81,6 +81,7 @@ fn counter_add(c: &mut Criterion) {
81
81
} ) ;
82
82
83
83
c. bench_function ( "Counter_Add_Unsorted" , |b| {
84
+ let counter = create_counter ( "Counter_Add_Unsorted" ) ;
84
85
b. iter ( || {
85
86
// 4*4*10*10 = 1600 time series.
86
87
let rands = CURRENT_RNG . with ( |rng| {
@@ -108,11 +109,13 @@ fn counter_add(c: &mut Criterion) {
108
109
} ) ;
109
110
} ) ;
110
111
111
- // Cause overflow.
112
- for v in 0 ..2001 {
113
- counter. add ( 100 , & [ KeyValue :: new ( "A" , v. to_string ( ) ) ] ) ;
114
- }
115
112
c. bench_function ( "Counter_Overflow" , |b| {
113
+ let counter = create_counter ( "Counter_Overflow" ) ;
114
+ // Cause overflow.
115
+ for v in 0 ..2001 {
116
+ counter. add ( 100 , & [ KeyValue :: new ( "A" , v. to_string ( ) ) ] ) ;
117
+ }
118
+
116
119
b. iter ( || {
117
120
// 4*4*10*10 = 1600 time series.
118
121
let rands = CURRENT_RNG . with ( |rng| {
0 commit comments