MCPcopy Create free account
hub / github.com/segmentio/encoding / codeInit

Function codeInit

json/golang_bench_test.go:46–83  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44)
45
46func codeInit() {
47 f, err := os.Open("testdata/code.json.gz")
48 if err != nil {
49 panic(err)
50 }
51 defer f.Close()
52 gz, err := gzip.NewReader(f)
53 if err != nil {
54 panic(err)
55 }
56 data, err := io.ReadAll(gz)
57 if err != nil {
58 panic(err)
59 }
60
61 codeJSON = data
62
63 if err := Unmarshal(codeJSON, &codeStruct); err != nil {
64 panic("unmarshal code.json: " + err.Error())
65 }
66
67 if data, err = Marshal(&codeStruct); err != nil {
68 panic("marshal code.json: " + err.Error())
69 }
70
71 if !bytes.Equal(data, codeJSON) {
72 println("different lengths", len(data), len(codeJSON))
73 for i := range min(len(data), len(codeJSON)) {
74 if data[i] != codeJSON[i] {
75 println("re-marshal: changed at byte", i)
76 println("orig: ", string(codeJSON[i-10:i+10]))
77 println("new: ", string(data[i-10:i+10]))
78 break
79 }
80 }
81 panic("re-marshal code.json: different result")
82 }
83}
84
85func BenchmarkCodeEncoder(b *testing.B) {
86 b.ReportAllocs()

Callers 5

BenchmarkCodeEncoderFunction · 0.85
BenchmarkCodeMarshalFunction · 0.85
BenchmarkCodeDecoderFunction · 0.85
BenchmarkCodeUnmarshalFunction · 0.85

Calls 4

UnmarshalFunction · 0.70
MarshalFunction · 0.70
NewReaderMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…