...

Source file src/github.com/launchdarkly/go-sdk-common/v3/ldvalue/value_json_conversion_benchmark_test.go

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

     1  package ldvalue
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  )
     7  
     8  func makeComplexValue() Value {
     9  	longArray := ArrayBuild()
    10  	for i := 0; i < 50; i++ {
    11  		longArray.Add(String(fmt.Sprintf("value%d", i)))
    12  	}
    13  	return ObjectBuild().
    14  		Set("prop1", String("simple string")).
    15  		Set("prop2", String("string\twith\"escapes\"")).
    16  		Set("prop3", longArray.Build()).
    17  		Set("prop4", ObjectBuild().Set("sub1", Int(1)).Set("sub2", Int(2)).Build()).
    18  		Build()
    19  }
    20  
    21  func BenchmarkSerializeComplexValue(b *testing.B) {
    22  	value := makeComplexValue()
    23  	b.ResetTimer()
    24  	for i := 0; i < b.N; i++ {
    25  		benchmarkJSONResult, benchmarkErrResult = value.MarshalJSON()
    26  	}
    27  }
    28  
    29  func BenchmarkDeserializeComplexValue(b *testing.B) {
    30  	data, _ := makeComplexValue().MarshalJSON()
    31  	b.ResetTimer()
    32  	for i := 0; i < b.N; i++ {
    33  		benchmarkValueResult.UnmarshalJSON(data)
    34  	}
    35  }
    36  

View as plain text