1
- use criterion:: { black_box , criterion_group, criterion_main, Criterion } ;
1
+ use criterion:: { criterion_group, criterion_main, Criterion } ;
2
2
use opentelemetry:: {
3
3
metrics:: { noop:: NoopMeterProvider , Counter , MeterProvider as _} ,
4
4
KeyValue ,
5
5
} ;
6
6
7
+ // Run this benchmark with:
8
+ // cargo bench --bench metrics --features=metrics
9
+
7
10
fn create_counter ( ) -> Counter < u64 > {
8
11
let meter_provider: NoopMeterProvider = NoopMeterProvider :: default ( ) ;
9
12
let meter = meter_provider. meter ( "benchmarks" ) ;
@@ -12,21 +15,21 @@ fn create_counter() -> Counter<u64> {
12
15
}
13
16
14
17
fn criterion_benchmark ( c : & mut Criterion ) {
15
- noop_counter_add ( c) ;
18
+ counter_add ( c) ;
16
19
}
17
20
18
- fn noop_counter_add ( c : & mut Criterion ) {
19
- let noop_counter = create_counter ( ) ;
21
+ fn counter_add ( c : & mut Criterion ) {
22
+ let counter = create_counter ( ) ;
20
23
21
- c. bench_function ( "NoopCounter_NoAttributes " , |b| {
24
+ c. bench_function ( "Counter_NoAttributes " , |b| {
22
25
b. iter ( || {
23
- noop_counter . add ( 1 , & [ ] ) ;
26
+ counter . add ( 1 , & [ ] ) ;
24
27
} ) ;
25
28
} ) ;
26
29
27
- c. bench_function ( "NoopCounter_AddWithInlineStaticAttributes " , |b| {
30
+ c. bench_function ( "Counter_AddWithInlineStaticAttributes " , |b| {
28
31
b. iter ( || {
29
- noop_counter . add (
32
+ counter . add (
30
33
1 ,
31
34
& [
32
35
KeyValue :: new ( "attribute1" , "value1" ) ,
@@ -38,7 +41,7 @@ fn noop_counter_add(c: &mut Criterion) {
38
41
} ) ;
39
42
} ) ;
40
43
41
- c. bench_function ( "NoopCounter_AddWithStaticArray " , |b| {
44
+ c. bench_function ( "Counter_AddWithStaticArray " , |b| {
42
45
b. iter ( || {
43
46
let kv = [
44
47
KeyValue :: new ( "attribute1" , "value1" ) ,
@@ -47,11 +50,11 @@ fn noop_counter_add(c: &mut Criterion) {
47
50
KeyValue :: new ( "attribute4" , "value4" ) ,
48
51
] ;
49
52
50
- noop_counter . add ( 1 , & kv) ;
53
+ counter . add ( 1 , & kv) ;
51
54
} ) ;
52
55
} ) ;
53
56
54
- c. bench_function ( "NoopCounter_AddWithDynamicAttributes " , |b| {
57
+ c. bench_function ( "Counter_AddWithDynamicAttributes " , |b| {
55
58
b. iter ( || {
56
59
let kv = vec ! [
57
60
KeyValue :: new( "attribute1" , "value1" ) ,
@@ -60,31 +63,7 @@ fn noop_counter_add(c: &mut Criterion) {
60
63
KeyValue :: new( "attribute4" , "value4" ) ,
61
64
] ;
62
65
63
- noop_counter. add ( 1 , & kv) ;
64
- } ) ;
65
- } ) ;
66
-
67
- #[ allow( clippy:: useless_vec) ]
68
- c. bench_function ( "CreateVector_KeyValue" , |b| {
69
- b. iter ( || {
70
- let _v1 = black_box ( vec ! [
71
- KeyValue :: new( "attribute1" , "value1" ) ,
72
- KeyValue :: new( "attribute2" , "value2" ) ,
73
- KeyValue :: new( "attribute3" , "value3" ) ,
74
- KeyValue :: new( "attribute4" , "value4" ) ,
75
- ] ) ;
76
- } ) ;
77
- } ) ;
78
-
79
- #[ allow( clippy:: useless_vec) ]
80
- c. bench_function ( "CreateDynamicVector_StringPair" , |b| {
81
- b. iter ( || {
82
- let _v1 = black_box ( vec ! [
83
- ( "attribute1" , "value1" ) ,
84
- ( "attribute2" , "value2" ) ,
85
- ( "attribute3" , "value3" ) ,
86
- ( "attribute4" , "value4" ) ,
87
- ] ) ;
66
+ counter. add ( 1 , & kv) ;
88
67
} ) ;
89
68
} ) ;
90
69
}
0 commit comments