1
1
use criterion:: { black_box, criterion_group, criterion_main, Criterion } ;
2
- use opentelemetry:: KeyValue ;
2
+ use opentelemetry:: { Key , KeyValue } ;
3
+ use std:: sync:: Arc ;
3
4
4
5
// Run this benchmark with:
5
6
// cargo bench --bench attributes
@@ -9,20 +10,38 @@ fn criterion_benchmark(c: &mut Criterion) {
9
10
}
10
11
11
12
fn attributes_creation ( c : & mut Criterion ) {
13
+ c. bench_function ( "CreateOTelKey_Static" , |b| {
14
+ b. iter ( || {
15
+ let _v1 = black_box ( Key :: new ( "attribute1" ) ) ;
16
+ } ) ;
17
+ } ) ;
18
+
19
+ c. bench_function ( "CreateOTelKey_Owned" , |b| {
20
+ b. iter ( || {
21
+ let _v1 = black_box ( Key :: new ( String :: from ( "attribute1" ) ) ) ;
22
+ } ) ;
23
+ } ) ;
24
+
25
+ c. bench_function ( "CreateOTelKey_Arc" , |b| {
26
+ b. iter ( || {
27
+ let _v1 = black_box ( Key :: new ( Arc :: from ( "attribute1" ) ) ) ;
28
+ } ) ;
29
+ } ) ;
30
+
12
31
c. bench_function ( "CreateOTelKeyValue" , |b| {
13
32
b. iter ( || {
14
33
let _v1 = black_box ( KeyValue :: new ( "attribute1" , "value1" ) ) ;
15
34
} ) ;
16
35
} ) ;
17
36
18
- c. bench_function ( "CreateKeyValueTuple " , |b| {
37
+ c. bench_function ( "CreateTupleKeyValue " , |b| {
19
38
b. iter ( || {
20
39
let _v1 = black_box ( ( "attribute1" , "value1" ) ) ;
21
40
} ) ;
22
41
} ) ;
23
42
24
43
#[ allow( clippy:: useless_vec) ]
25
- c. bench_function ( "CreateVector_KeyValue " , |b| {
44
+ c. bench_function ( "CreateOtelKeyValueVector " , |b| {
26
45
b. iter ( || {
27
46
let _v1 = black_box ( vec ! [
28
47
KeyValue :: new( "attribute1" , "value1" ) ,
@@ -34,7 +53,7 @@ fn attributes_creation(c: &mut Criterion) {
34
53
} ) ;
35
54
36
55
#[ allow( clippy:: useless_vec) ]
37
- c. bench_function ( "CreateVector_StringPairs " , |b| {
56
+ c. bench_function ( "CreateTupleKeyValueVector " , |b| {
38
57
b. iter ( || {
39
58
let _v1 = black_box ( vec ! [
40
59
( "attribute1" , "value1" ) ,
0 commit comments