1
- use criterion:: { criterion_group, criterion_main, Criterion } ;
1
+ use criterion:: { black_box , criterion_group, criterion_main, BatchSize , Criterion } ;
2
2
use opentelemetry:: { global, metrics:: Counter , KeyValue } ;
3
3
4
4
// Run this benchmark with:
@@ -28,10 +28,10 @@ fn counter_add(c: &mut Criterion) {
28
28
counter. add (
29
29
1 ,
30
30
& [
31
- KeyValue :: new ( "attribute1" , "value1" ) ,
32
- KeyValue :: new ( "attribute2" , "value2" ) ,
33
- KeyValue :: new ( "attribute3" , "value3" ) ,
34
- KeyValue :: new ( "attribute4" , "value4" ) ,
31
+ black_box ( KeyValue :: new ( "attribute1" , "value1" ) ) ,
32
+ black_box ( KeyValue :: new ( "attribute2" , "value2" ) ) ,
33
+ black_box ( KeyValue :: new ( "attribute3" , "value3" ) ) ,
34
+ black_box ( KeyValue :: new ( "attribute4" , "value4" ) ) ,
35
35
] ,
36
36
) ;
37
37
} ) ;
@@ -51,16 +51,26 @@ fn counter_add(c: &mut Criterion) {
51
51
} ) ;
52
52
53
53
c. bench_function ( "Counter_AddWithDynamicAttributes" , |b| {
54
- b. iter ( || {
55
- let kv = vec ! [
56
- KeyValue :: new( "attribute1" , "value1" ) ,
57
- KeyValue :: new( "attribute2" , "value2" ) ,
58
- KeyValue :: new( "attribute3" , "value3" ) ,
59
- KeyValue :: new( "attribute4" , "value4" ) ,
60
- ] ;
54
+ b. iter_batched (
55
+ || {
56
+ let value1 = black_box ( "a" . repeat ( 6 ) ) ; // Repeat character six times to match the length of value strings used in other benchmarks
57
+ let value2 = black_box ( "b" . repeat ( 6 ) ) ;
58
+ let value3 = black_box ( "c" . repeat ( 6 ) ) ;
59
+ let value4 = black_box ( "d" . repeat ( 6 ) ) ;
61
60
62
- counter. add ( 1 , & kv) ;
63
- } ) ;
61
+ ( value1, value2, value3, value4)
62
+ } ,
63
+ |values| {
64
+ let kv = & [
65
+ KeyValue :: new ( "attribute1" , values. 0 ) ,
66
+ KeyValue :: new ( "attribute2" , values. 1 ) ,
67
+ KeyValue :: new ( "attribute3" , values. 2 ) ,
68
+ KeyValue :: new ( "attribute4" , values. 3 ) ,
69
+ ] ;
70
+
71
+ counter. add ( 1 , kv) ;
72
+ } ,
73
+ BatchSize :: SmallInput ) ;
64
74
} ) ;
65
75
}
66
76
0 commit comments