...
1 package ldcontext
2
3 import (
4 "fmt"
5 "testing"
6
7 "github.com/launchdarkly/go-sdk-common/v3/internal/sharedtest"
8 )
9
10
11
12 func BenchmarkNewNoAlloc(b *testing.B) {
13 for i := 0; i < b.N; i++ {
14 benchmarkContext = New("key")
15 }
16 }
17
18 func BenchmarkBuildFromLocalBuilderNoCustomAttrsNoAlloc(b *testing.B) {
19 for i := 0; i < b.N; i++ {
20 var b Builder
21 b.Key("key")
22 b.Name("x")
23 benchmarkContext = b.Build()
24 }
25 }
26
27 func BenchmarkBuildWithNoCustomAttrs(b *testing.B) {
28 for i := 0; i < b.N; i++ {
29 benchmarkContext = NewBuilder("key").Name("x").Build()
30 }
31 }
32
33 func BenchmarkBuildWithCustomAttributes(b *testing.B) {
34 for _, n := range []int{sharedtest.SmallNumberOfCustomAttributes, sharedtest.LargeNumberOfCustomAttributes} {
35 b.Run(fmt.Sprintf("with %d attributes", n), func(b *testing.B) {
36 attrs := sharedtest.MakeCustomAttributeNamesAndValues(n)
37 b.ResetTimer()
38 for i := 0; i < b.N; i++ {
39 builder := NewBuilder("key")
40 for _, a := range attrs {
41 builder.SetValue(a.Name, a.Value)
42 }
43 benchmarkContext = builder.Build()
44 }
45 })
46 }
47 }
48
49 func BenchmarkBuildWithPrivate(b *testing.B) {
50 for i := 0; i < b.N; i++ {
51 benchmarkContext = NewBuilder("key").Name("name").Private("name").Build()
52 }
53 }
54
View as plain text