...

Source file src/github.com/launchdarkly/go-sdk-common/v3/ldcontext/context_unmarshaling_benchmark_test.go

Documentation: github.com/launchdarkly/go-sdk-common/v3/ldcontext

     1  package ldcontext
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  // BenchmarkJSONUnmarshal uses json.Unmarshal; BenchmarkJSONStreamUnmarshal uses the jsonstream API via
     8  // ReadFromJSONReader. They both end up calling the same underlying logic, but json.Unmarshal has some
     9  // extra indirection.
    10  //
    11  // Unmarshaling via EasyJSON is covered in the conditionally-compiled file context_easyjson_benchmark_test.go.
    12  
    13  func doUnmarshalBenchmark(b *testing.B, unmarshalFn func(*Context, []byte) error) {
    14  	for _, p := range makeBenchmarkUnmarshalTestParams() {
    15  		b.Run(p.Name, func(b *testing.B) {
    16  			for i := 0; i < b.N; i++ {
    17  				if benchmarkErr = unmarshalFn(&benchmarkContext, p.Data); benchmarkErr != nil {
    18  					b.Fatal(benchmarkErr)
    19  				}
    20  			}
    21  		})
    22  	}
    23  }
    24  
    25  func BenchmarkJSONUnmarshal(b *testing.B) {
    26  	doUnmarshalBenchmark(b, jsonUnmarshalTestFn)
    27  }
    28  
    29  func BenchmarkJSONStreamUnmarshal(b *testing.B) {
    30  	doUnmarshalBenchmark(b, jsonStreamUnmarshalTestFn)
    31  }
    32  

View as plain text