6
6
RAM: 64.0 GB
7
7
| Test | Average time|
8
8
|--------------------------------|-------------|
9
- | Counter_Add_Sorted | 586 ns |
10
- | Counter_Add_Unsorted | 592 ns |
11
- | Counter_Overflow | 600 ns |
9
+ | Counter_Add_Sorted | 560 ns |
10
+ | Counter_Add_Unsorted | 565 ns |
11
+ | Counter_Overflow | 568 ns |
12
12
| ThreadLocal_Random_Generator_5 | 37 ns |
13
13
*/
14
14
@@ -30,6 +30,11 @@ thread_local! {
30
30
static CURRENT_RNG : RefCell <rngs:: SmallRng > = RefCell :: new( rngs:: SmallRng :: from_entropy( ) ) ;
31
31
}
32
32
33
+ static ATTRIBUTE_VALUES : [ & str ; 10 ] = [
34
+ "value1" , "value2" , "value3" , "value4" , "value5" , "value6" , "value7" , "value8" , "value9" ,
35
+ "value10" ,
36
+ ] ;
37
+
33
38
// Run this benchmark with:
34
39
// cargo bench --bench metric_counter
35
40
fn create_counter ( name : & ' static str ) -> Counter < u64 > {
@@ -38,21 +43,20 @@ fn create_counter(name: &'static str) -> Counter<u64> {
38
43
. build ( ) ;
39
44
let meter = meter_provider. meter ( "benchmarks" ) ;
40
45
46
+ println ! ( "Counter_Created" ) ;
41
47
meter. u64_counter ( name) . init ( )
42
48
}
43
49
44
50
fn criterion_benchmark ( c : & mut Criterion ) {
45
- counter_add ( c) ;
51
+ counter_add_sorted ( c) ;
52
+ counter_add_unsorted ( c) ;
53
+ counter_overflow ( c) ;
54
+ random_generator ( c) ;
46
55
}
47
56
48
- fn counter_add ( c : & mut Criterion ) {
49
- let attribute_values = [
50
- "value1" , "value2" , "value3" , "value4" , "value5" , "value6" , "value7" , "value8" , "value9" ,
51
- "value10" ,
52
- ] ;
53
-
57
+ fn counter_add_sorted ( c : & mut Criterion ) {
58
+ let counter = create_counter ( "Counter_Add_Sorted" ) ;
54
59
c. bench_function ( "Counter_Add_Sorted" , |b| {
55
- let counter = create_counter ( "Counter_Add_Sorted" ) ;
56
60
b. iter ( || {
57
61
// 4*4*10*10 = 1600 time series.
58
62
let rands = CURRENT_RNG . with ( |rng| {
@@ -71,17 +75,19 @@ fn counter_add(c: &mut Criterion) {
71
75
counter. add (
72
76
1 ,
73
77
& [
74
- KeyValue :: new ( "attribute1" , attribute_values [ index_first_attribute] ) ,
75
- KeyValue :: new ( "attribute2" , attribute_values [ index_second_attribute] ) ,
76
- KeyValue :: new ( "attribute3" , attribute_values [ index_third_attribute] ) ,
77
- KeyValue :: new ( "attribute4" , attribute_values [ index_fourth_attribute] ) ,
78
+ KeyValue :: new ( "attribute1" , ATTRIBUTE_VALUES [ index_first_attribute] ) ,
79
+ KeyValue :: new ( "attribute2" , ATTRIBUTE_VALUES [ index_second_attribute] ) ,
80
+ KeyValue :: new ( "attribute3" , ATTRIBUTE_VALUES [ index_third_attribute] ) ,
81
+ KeyValue :: new ( "attribute4" , ATTRIBUTE_VALUES [ index_fourth_attribute] ) ,
78
82
] ,
79
83
) ;
80
84
} ) ;
81
85
} ) ;
86
+ }
82
87
88
+ fn counter_add_unsorted ( c : & mut Criterion ) {
89
+ let counter = create_counter ( "Counter_Add_Unsorted" ) ;
83
90
c. bench_function ( "Counter_Add_Unsorted" , |b| {
84
- let counter = create_counter ( "Counter_Add_Unsorted" ) ;
85
91
b. iter ( || {
86
92
// 4*4*10*10 = 1600 time series.
87
93
let rands = CURRENT_RNG . with ( |rng| {
@@ -100,22 +106,24 @@ fn counter_add(c: &mut Criterion) {
100
106
counter. add (
101
107
1 ,
102
108
& [
103
- KeyValue :: new ( "attribute2" , attribute_values [ index_second_attribute] ) ,
104
- KeyValue :: new ( "attribute3" , attribute_values [ index_third_attribute] ) ,
105
- KeyValue :: new ( "attribute1" , attribute_values [ index_first_attribute] ) ,
106
- KeyValue :: new ( "attribute4" , attribute_values [ index_fourth_attribute] ) ,
109
+ KeyValue :: new ( "attribute2" , ATTRIBUTE_VALUES [ index_second_attribute] ) ,
110
+ KeyValue :: new ( "attribute3" , ATTRIBUTE_VALUES [ index_third_attribute] ) ,
111
+ KeyValue :: new ( "attribute1" , ATTRIBUTE_VALUES [ index_first_attribute] ) ,
112
+ KeyValue :: new ( "attribute4" , ATTRIBUTE_VALUES [ index_fourth_attribute] ) ,
107
113
] ,
108
114
) ;
109
115
} ) ;
110
116
} ) ;
117
+ }
111
118
112
- c . bench_function ( "Counter_Overflow" , |b| {
113
- let counter = create_counter ( "Counter_Overflow" ) ;
114
- // Cause overflow.
115
- for v in 0 ..2001 {
116
- counter. add ( 100 , & [ KeyValue :: new ( "A" , v. to_string ( ) ) ] ) ;
117
- }
119
+ fn counter_overflow ( c : & mut Criterion ) {
120
+ let counter = create_counter ( "Counter_Overflow" ) ;
121
+ // Cause overflow.
122
+ for v in 0 ..2001 {
123
+ counter. add ( 100 , & [ KeyValue :: new ( "A" , v. to_string ( ) ) ] ) ;
124
+ }
118
125
126
+ c. bench_function ( "Counter_Overflow" , |b| {
119
127
b. iter ( || {
120
128
// 4*4*10*10 = 1600 time series.
121
129
let rands = CURRENT_RNG . with ( |rng| {
@@ -134,15 +142,17 @@ fn counter_add(c: &mut Criterion) {
134
142
counter. add (
135
143
1 ,
136
144
& [
137
- KeyValue :: new ( "attribute1 " , attribute_values [ index_first_attribute ] ) ,
138
- KeyValue :: new ( "attribute2 " , attribute_values [ index_second_attribute ] ) ,
139
- KeyValue :: new ( "attribute3 " , attribute_values [ index_third_attribute ] ) ,
140
- KeyValue :: new ( "attribute4" , attribute_values [ index_fourth_attribute] ) ,
145
+ KeyValue :: new ( "attribute2 " , ATTRIBUTE_VALUES [ index_second_attribute ] ) ,
146
+ KeyValue :: new ( "attribute3 " , ATTRIBUTE_VALUES [ index_third_attribute ] ) ,
147
+ KeyValue :: new ( "attribute1 " , ATTRIBUTE_VALUES [ index_first_attribute ] ) ,
148
+ KeyValue :: new ( "attribute4" , ATTRIBUTE_VALUES [ index_fourth_attribute] ) ,
141
149
] ,
142
150
) ;
143
151
} ) ;
144
152
} ) ;
153
+ }
145
154
155
+ fn random_generator ( c : & mut Criterion ) {
146
156
c. bench_function ( "ThreadLocal_Random_Generator_5" , |b| {
147
157
b. iter ( || {
148
158
let __i1 = CURRENT_RNG . with ( |rng| {
0 commit comments