...

Source file src/github.com/launchdarkly/go-server-sdk-evaluation/v2/evaluator_bucketing_bench_test.go

Documentation: github.com/launchdarkly/go-server-sdk-evaluation/v2

     1  package evaluation
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/launchdarkly/go-sdk-common/v3/ldattr"
     7  	"github.com/launchdarkly/go-sdk-common/v3/ldcontext"
     8  	"github.com/launchdarkly/go-sdk-common/v3/ldvalue"
     9  )
    10  
    11  func BenchmarkComputeBucketValueNoAlloc(b *testing.B) {
    12  	for _, p := range []struct {
    13  		name       string
    14  		customAttr ldvalue.Value
    15  		seed       ldvalue.OptionalInt
    16  	}{
    17  		{
    18  			name: "simple",
    19  		},
    20  		{
    21  			name: "with seed",
    22  			seed: ldvalue.NewOptionalInt(42),
    23  		},
    24  		{
    25  			name:       "bucket by custom attr string",
    26  			customAttr: ldvalue.String("xyz"),
    27  		},
    28  		{
    29  			name:       "bucket by custom attr int",
    30  			customAttr: ldvalue.Int(123),
    31  		},
    32  	} {
    33  		b.Run(p.name, func(b *testing.B) {
    34  			builder := ldcontext.NewBuilder("userKey")
    35  			if p.customAttr.IsDefined() {
    36  				builder.SetValue("attr1", p.customAttr)
    37  			}
    38  			context := builder.Build()
    39  			evalScope := makeEvalScope(context)
    40  
    41  			var bucketBy ldattr.Ref
    42  			if p.customAttr.IsDefined() {
    43  				bucketBy = ldattr.NewLiteralRef("attr1")
    44  			}
    45  
    46  			b.ResetTimer()
    47  
    48  			for i := 0; i < b.N; i++ {
    49  				_, _, evalBenchmarkErr = evalScope.computeBucketValue(false, p.seed, "", "hashKey", bucketBy, "saltyA")
    50  			}
    51  		})
    52  	}
    53  }
    54  

View as plain text