@@ -15,6 +15,7 @@ package model
15
15
16
16
import (
17
17
"runtime"
18
+ "sync"
18
19
"testing"
19
20
)
20
21
@@ -216,3 +217,40 @@ func TestEmptyLabelSignature(t *testing.T) {
216
217
t .Fatal ("expected LabelsToSignature with empty labels not to perform allocations" )
217
218
}
218
219
}
220
+
221
+ func benchmarkMetricToFingerprintConc (b * testing.B , m Metric , e Fingerprint , concLevel int ) {
222
+ var start , end sync.WaitGroup
223
+ start .Add (1 )
224
+ end .Add (concLevel )
225
+
226
+ for i := 0 ; i < concLevel ; i ++ {
227
+ go func () {
228
+ start .Wait ()
229
+ for j := b .N / concLevel ; j >= 0 ; j -- {
230
+ if a := metricToFingerprint (m ); a != e {
231
+ b .Fatalf ("expected signature of %d for %s, got %d" , e , m , a )
232
+ }
233
+ }
234
+ end .Done ()
235
+ }()
236
+ }
237
+ b .ResetTimer ()
238
+ start .Done ()
239
+ end .Wait ()
240
+ }
241
+
242
+ func BenchmarkMetricToFingerprintTripleConc1 (b * testing.B ) {
243
+ benchmarkMetricToFingerprintConc (b , Metric {"first-label" : "first-label-value" , "second-label" : "second-label-value" , "third-label" : "third-label-value" }, 15738406913934009676 , 1 )
244
+ }
245
+
246
+ func BenchmarkMetricToFingerprintTripleConc2 (b * testing.B ) {
247
+ benchmarkMetricToFingerprintConc (b , Metric {"first-label" : "first-label-value" , "second-label" : "second-label-value" , "third-label" : "third-label-value" }, 15738406913934009676 , 2 )
248
+ }
249
+
250
+ func BenchmarkMetricToFingerprintTripleConc4 (b * testing.B ) {
251
+ benchmarkMetricToFingerprintConc (b , Metric {"first-label" : "first-label-value" , "second-label" : "second-label-value" , "third-label" : "third-label-value" }, 15738406913934009676 , 4 )
252
+ }
253
+
254
+ func BenchmarkMetricToFingerprintTripleConc8 (b * testing.B ) {
255
+ benchmarkMetricToFingerprintConc (b , Metric {"first-label" : "first-label-value" , "second-label" : "second-label-value" , "third-label" : "third-label-value" }, 15738406913934009676 , 8 )
256
+ }
0 commit comments