forked from DataDog/datadog-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontext_resolver_bench_test.go
50 lines (40 loc) · 1.26 KB
/
context_resolver_bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package aggregator
import (
"strconv"
"testing"
"github.com/DataDog/datadog-agent/pkg/aggregator/internal/tags"
"github.com/DataDog/datadog-agent/pkg/metrics"
)
func benchmarkContextResolver(numContexts int, b *testing.B) {
var samples []metrics.MetricSample
for i := 0; i < numContexts; i++ {
samples = append(samples, metrics.MetricSample{
Name: "my.metric.name",
Value: 1,
Mtype: metrics.GaugeType,
Tags: []string{"foo", "bar", strconv.Itoa(i)},
SampleRate: 1,
})
}
cache := tags.NewStore(true, "test")
cr := newContextResolver(cache, "0")
b.ResetTimer()
for n := 0; n < b.N; n++ {
cr.trackContext(&samples[n%numContexts], 0)
}
b.ReportAllocs()
}
// Benchmark context tracking with different number of contexts.
func BenchmarkContextResolver1(b *testing.B) {
benchmarkContextResolver(1, b)
}
func BenchmarkContextResolver1000(b *testing.B) {
benchmarkContextResolver(1000, b)
}
func BenchmarkContextResolver1000000(b *testing.B) {
benchmarkContextResolver(1000000, b)
}