@@ -5,12 +5,45 @@ use rand::Rng;
5
5
6
6
const MAX_KEY_VALUE_PAIRS : usize = 64 ;
7
7
8
+ // Run this benchmark with:
9
+ // cargo bench --bench baggage
10
+ // Adding results in comments for a quick reference.
11
+ // Apple M4 Pro
12
+ // Total Number of Cores: 14 (10 performance and 4 efficiency)
13
+ // Results:
14
+ // set_baggage_static_key_value 12 ns
15
+ // set_baggage_static_key 28 ns
16
+ // set_baggage_dynamic 60 ns
17
+ // set_baggage_dynamic_with_metadata 112 ns
18
+
8
19
fn criterion_benchmark ( c : & mut Criterion ) {
9
- set_baggage_value ( c) ;
10
- set_baggage_value_with_metadata ( c) ;
20
+ set_baggage_static_key_value ( c) ;
21
+ set_baggage_static_key ( c) ;
22
+ set_baggage_dynamic ( c) ;
23
+ set_baggage_dynamic_with_metadata ( c) ;
24
+ }
25
+
26
+ fn set_baggage_static_key_value ( c : & mut Criterion ) {
27
+ let mut baggage = Baggage :: new ( ) ;
28
+
29
+ c. bench_function ( "set_baggage_static_key_value" , move |b| {
30
+ b. iter ( || {
31
+ baggage. insert ( "key" , "value" ) ;
32
+ } )
33
+ } ) ;
34
+ }
35
+
36
+ fn set_baggage_static_key ( c : & mut Criterion ) {
37
+ let mut baggage = Baggage :: new ( ) ;
38
+
39
+ c. bench_function ( "set_baggage_static_key" , move |b| {
40
+ b. iter ( || {
41
+ baggage. insert ( "key" , "value" . to_string ( ) ) ;
42
+ } )
43
+ } ) ;
11
44
}
12
45
13
- fn set_baggage_value ( c : & mut Criterion ) {
46
+ fn set_baggage_dynamic ( c : & mut Criterion ) {
14
47
let mut baggage = Baggage :: new ( ) ;
15
48
16
49
let mut rng = rand:: rng ( ) ;
@@ -23,7 +56,7 @@ fn set_baggage_value(c: &mut Criterion) {
23
56
} )
24
57
. collect :: < Vec < ( String , String ) > > ( ) ;
25
58
26
- c. bench_function ( "set_baggage_value " , move |b| {
59
+ c. bench_function ( "set_baggage_dynamic " , move |b| {
27
60
b. iter_batched (
28
61
|| rng. random_range ( 0 ..MAX_KEY_VALUE_PAIRS ) ,
29
62
|idx| {
@@ -35,7 +68,7 @@ fn set_baggage_value(c: &mut Criterion) {
35
68
} ) ;
36
69
}
37
70
38
- fn set_baggage_value_with_metadata ( c : & mut Criterion ) {
71
+ fn set_baggage_dynamic_with_metadata ( c : & mut Criterion ) {
39
72
let mut baggage = Baggage :: new ( ) ;
40
73
41
74
let mut rng = rand:: rng ( ) ;
@@ -49,7 +82,7 @@ fn set_baggage_value_with_metadata(c: &mut Criterion) {
49
82
} )
50
83
. collect :: < Vec < ( String , String , String ) > > ( ) ;
51
84
52
- c. bench_function ( "set_baggage_value_with_metadata " , move |b| {
85
+ c. bench_function ( "set_baggage_dynamic_with_metadata " , move |b| {
53
86
b. iter_batched (
54
87
|| rng. random_range ( 0 ..MAX_KEY_VALUE_PAIRS ) ,
55
88
|idx| {
0 commit comments