@@ -17,6 +17,7 @@ use prometheus::{Counter, CounterVec, IntCounter, Opts};
17
17
use std:: collections:: HashMap ;
18
18
use std:: sync:: { atomic, Arc } ;
19
19
use std:: thread;
20
+ use rapidhash:: RapidBuildHasher ;
20
21
21
22
fn bench_counter_with_label_values ( c : & mut Criterion ) {
22
23
let counter = CounterVec :: new (
@@ -69,6 +70,132 @@ fn bench_counter_with_mapped_labels_fnv(c: &mut Criterion) {
69
70
} ) ;
70
71
}
71
72
73
+ fn bench_counter_with_mapped_labels_rapidhash ( c : & mut Criterion ) {
74
+ let counter = CounterVec :: new (
75
+ Opts :: new ( "benchmark_counter" , "A counter to benchmark it." ) ,
76
+ & [ "one" , "two" , "three" ] ,
77
+ )
78
+ . unwrap ( ) ;
79
+
80
+ c. bench_function ( "counter_with_mapped_labels_rapidhash" , |b| {
81
+ b. iter ( || {
82
+ let mut labels = HashMap :: with_capacity_and_hasher ( 3 , RapidBuildHasher :: default ( ) ) ;
83
+ labels. insert ( "two" , "zwei" ) ;
84
+ labels. insert ( "one" , "eins" ) ;
85
+ labels. insert ( "three" , "drei" ) ;
86
+ counter. with ( & black_box ( labels) ) . inc ( ) ;
87
+ } )
88
+ } ) ;
89
+ }
90
+
91
+ fn bench_counter_with_mapped_mid_labels ( c : & mut Criterion ) {
92
+ let counter = CounterVec :: new (
93
+ Opts :: new ( "benchmark_counter" , "A counter to benchmark it." ) ,
94
+ & [ "midsize_one" , "midsize_two" , "midsize_three" ] ,
95
+ )
96
+ . unwrap ( ) ;
97
+
98
+ c. bench_function ( "counter_with_mapped_mid_labels" , |b| {
99
+ b. iter ( || {
100
+ let mut labels = HashMap :: with_capacity ( 3 ) ;
101
+ labels. insert ( "midsize_two" , "midsize_zwei" ) ;
102
+ labels. insert ( "midsize_one" , "midsize_eins" ) ;
103
+ labels. insert ( "midsize_three" , "midsize_drei" ) ;
104
+ counter. with ( & black_box ( labels) ) . inc ( ) ;
105
+ } )
106
+ } ) ;
107
+ }
108
+
109
+ fn bench_counter_with_mapped_mid_labels_fnv ( c : & mut Criterion ) {
110
+ let counter = CounterVec :: new (
111
+ Opts :: new ( "benchmark_counter" , "A counter to benchmark it." ) ,
112
+ & [ "midsize_one" , "midsize_two" , "midsize_three" ] ,
113
+ )
114
+ . unwrap ( ) ;
115
+
116
+ c. bench_function ( "counter_with_mapped_mid_labels_fnv" , |b| {
117
+ b. iter ( || {
118
+ let mut labels = HashMap :: with_capacity_and_hasher ( 3 , FnvBuildHasher :: default ( ) ) ;
119
+ labels. insert ( "midsize_two" , "midsize_zwei" ) ;
120
+ labels. insert ( "midsize_one" , "midsize_eins" ) ;
121
+ labels. insert ( "midsize_three" , "midsize_drei" ) ;
122
+ counter. with ( & black_box ( labels) ) . inc ( ) ;
123
+ } )
124
+ } ) ;
125
+ }
126
+
127
+ fn bench_counter_with_mapped_mid_labels_rapidhash ( c : & mut Criterion ) {
128
+ let counter = CounterVec :: new (
129
+ Opts :: new ( "benchmark_counter" , "A counter to benchmark it." ) ,
130
+ & [ "midsize_one" , "midsize_two" , "midsize_three" ] ,
131
+ )
132
+ . unwrap ( ) ;
133
+
134
+ c. bench_function ( "counter_with_mapped_mid_labels_rapidhash" , |b| {
135
+ b. iter ( || {
136
+ let mut labels = HashMap :: with_capacity_and_hasher ( 3 , RapidBuildHasher :: default ( ) ) ;
137
+ labels. insert ( "midsize_two" , "midsize_zwei" ) ;
138
+ labels. insert ( "midsize_one" , "midsize_eins" ) ;
139
+ labels. insert ( "midsize_three" , "midsize_drei" ) ;
140
+ counter. with ( & black_box ( labels) ) . inc ( ) ;
141
+ } )
142
+ } ) ;
143
+ }
144
+
145
+ fn bench_counter_with_mapped_long_labels ( c : & mut Criterion ) {
146
+ let counter = CounterVec :: new (
147
+ Opts :: new ( "benchmark_counter" , "A counter to benchmark it." ) ,
148
+ & [ "longer_field_number_one" , "longer_field_number_two" , "longer_field_number_three" ] ,
149
+ )
150
+ . unwrap ( ) ;
151
+
152
+ c. bench_function ( "counter_with_mapped_longer_labels" , |b| {
153
+ b. iter ( || {
154
+ let mut labels = HashMap :: with_capacity ( 3 ) ;
155
+ labels. insert ( "longer_field_number_two" , "longer_field_number_zwei" ) ;
156
+ labels. insert ( "longer_field_number_one" , "longer_field_number_eins" ) ;
157
+ labels. insert ( "longer_field_number_three" , "longer_field_number_drei" ) ;
158
+ counter. with ( & black_box ( labels) ) . inc ( ) ;
159
+ } )
160
+ } ) ;
161
+ }
162
+
163
+ fn bench_counter_with_mapped_long_labels_fnv ( c : & mut Criterion ) {
164
+ let counter = CounterVec :: new (
165
+ Opts :: new ( "benchmark_counter" , "A counter to benchmark it." ) ,
166
+ & [ "longer_field_number_one" , "longer_field_number_two" , "longer_field_number_three" ] ,
167
+ )
168
+ . unwrap ( ) ;
169
+
170
+ c. bench_function ( "counter_with_mapped_longer_labels_fnv" , |b| {
171
+ b. iter ( || {
172
+ let mut labels = HashMap :: with_capacity_and_hasher ( 3 , FnvBuildHasher :: default ( ) ) ;
173
+ labels. insert ( "longer_field_number_two" , "longer_field_number_zwei" ) ;
174
+ labels. insert ( "longer_field_number_one" , "longer_field_number_eins" ) ;
175
+ labels. insert ( "longer_field_number_three" , "longer_field_number_drei" ) ;
176
+ counter. with ( & black_box ( labels) ) . inc ( ) ;
177
+ } )
178
+ } ) ;
179
+ }
180
+
181
+ fn bench_counter_with_mapped_long_labels_rapidhash ( c : & mut Criterion ) {
182
+ let counter = CounterVec :: new (
183
+ Opts :: new ( "benchmark_counter" , "A counter to benchmark it." ) ,
184
+ & [ "longer_field_number_one" , "longer_field_number_two" , "longer_field_number_three" ] ,
185
+ )
186
+ . unwrap ( ) ;
187
+
188
+ c. bench_function ( "counter_with_mapped_longer_labels_rapidhash" , |b| {
189
+ b. iter ( || {
190
+ let mut labels = HashMap :: with_capacity_and_hasher ( 3 , RapidBuildHasher :: default ( ) ) ;
191
+ labels. insert ( "longer_field_number_two" , "longer_field_number_zwei" ) ;
192
+ labels. insert ( "longer_field_number_one" , "longer_field_number_eins" ) ;
193
+ labels. insert ( "longer_field_number_three" , "longer_field_number_drei" ) ;
194
+ counter. with ( & black_box ( labels) ) . inc ( ) ;
195
+ } )
196
+ } ) ;
197
+ }
198
+
72
199
fn bench_counter_with_prepared_mapped_labels ( c : & mut Criterion ) {
73
200
let counter = CounterVec :: new (
74
201
Opts :: new ( "benchmark_counter" , "A counter to benchmark it." ) ,
@@ -216,6 +343,13 @@ criterion_group!(
216
343
bench_counter_with_label_values_concurrent_write,
217
344
bench_counter_with_mapped_labels,
218
345
bench_counter_with_mapped_labels_fnv,
346
+ bench_counter_with_mapped_labels_rapidhash,
347
+ bench_counter_with_mapped_mid_labels,
348
+ bench_counter_with_mapped_mid_labels_fnv,
349
+ bench_counter_with_mapped_mid_labels_rapidhash,
350
+ bench_counter_with_mapped_long_labels,
351
+ bench_counter_with_mapped_long_labels_fnv,
352
+ bench_counter_with_mapped_long_labels_rapidhash,
219
353
bench_counter_with_prepared_mapped_labels,
220
354
bench_int_counter_no_labels,
221
355
bench_int_counter_no_labels_concurrent_write,
0 commit comments