1
- use criterion:: { criterion_group, criterion_main, Criterion } ;
1
+ /*
2
+ Benchmark Results:
3
+ criterion = "0.5.1"
4
+ OS: Ubuntu 22.04.4 LTS (5.15.153.1-microsoft-standard-WSL2)
5
+ Hardware: Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz, 16vCPUs,
6
+ RAM: 64.0 GB
7
+ | Test | Average time|
8
+ |-----------------------------------------------------|-------------|
9
+ | NoAttributes | 1.1616 ns |
10
+ | AddWithInlineStaticAttributes | 13.296 ns |
11
+ | AddWithStaticArray | 1.1612 ns |
12
+ | AddWithDynamicAttributes | 110.40 ns |
13
+ | AddWithDynamicAttributes_WithStringAllocation | 77.338 ns |
14
+ */
15
+
16
+ use criterion:: { black_box, criterion_group, criterion_main, BatchSize , Criterion } ;
2
17
use opentelemetry:: { global, metrics:: Counter , KeyValue } ;
3
18
4
19
// Run this benchmark with:
@@ -17,13 +32,13 @@ fn criterion_benchmark(c: &mut Criterion) {
17
32
fn counter_add ( c : & mut Criterion ) {
18
33
let counter = create_counter ( ) ;
19
34
20
- c. bench_function ( "Counter_NoAttributes " , |b| {
35
+ c. bench_function ( "NoAttributes " , |b| {
21
36
b. iter ( || {
22
37
counter. add ( 1 , & [ ] ) ;
23
38
} ) ;
24
39
} ) ;
25
40
26
- c. bench_function ( "Counter_AddWithInlineStaticAttributes " , |b| {
41
+ c. bench_function ( "AddWithInlineStaticAttributes " , |b| {
27
42
b. iter ( || {
28
43
counter. add (
29
44
1 ,
@@ -44,22 +59,46 @@ fn counter_add(c: &mut Criterion) {
44
59
KeyValue :: new ( "attribute4" , "value4" ) ,
45
60
] ;
46
61
47
- c. bench_function ( "Counter_AddWithStaticArray " , |b| {
62
+ c. bench_function ( "AddWithStaticArray " , |b| {
48
63
b. iter ( || {
49
64
counter. add ( 1 , & kv) ;
50
65
} ) ;
51
66
} ) ;
52
67
53
- c. bench_function ( "Counter_AddWithDynamicAttributes" , |b| {
68
+ c. bench_function ( "AddWithDynamicAttributes" , |b| {
69
+ b. iter_batched (
70
+ || {
71
+ let value1 = "value1" . to_string ( ) ;
72
+ let value2 = "value2" . to_string ( ) ;
73
+ let value3 = "value3" . to_string ( ) ;
74
+ let value4 = "value4" . to_string ( ) ;
75
+
76
+ ( value1, value2, value3, value4)
77
+ } ,
78
+ |values| {
79
+ let kv = & [
80
+ KeyValue :: new ( "attribute1" , values. 0 ) ,
81
+ KeyValue :: new ( "attribute2" , values. 1 ) ,
82
+ KeyValue :: new ( "attribute3" , values. 2 ) ,
83
+ KeyValue :: new ( "attribute4" , values. 3 ) ,
84
+ ] ;
85
+
86
+ counter. add ( 1 , kv) ;
87
+ } ,
88
+ BatchSize :: SmallInput ,
89
+ ) ;
90
+ } ) ;
91
+
92
+ c. bench_function ( "AddWithDynamicAttributes_WithStringAllocation" , |b| {
54
93
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" ) ,
94
+ let kv = & [
95
+ KeyValue :: new ( "attribute1" , black_box ( "value1" . to_string ( ) ) ) ,
96
+ KeyValue :: new ( "attribute2" , black_box ( "value2" . to_string ( ) ) ) ,
97
+ KeyValue :: new ( "attribute3" , black_box ( "value3" . to_string ( ) ) ) ,
98
+ KeyValue :: new ( "attribute4" , black_box ( "value4" . to_string ( ) ) ) ,
60
99
] ;
61
100
62
- counter. add ( 1 , & kv) ;
101
+ counter. add ( 1 , kv) ;
63
102
} ) ;
64
103
} ) ;
65
104
}
0 commit comments