MCPcopy
hub / github.com/tinylib/msgp / BenchmarkUnmarshalAsJSON

Function BenchmarkUnmarshalAsJSON

msgp/json_bytes_test.go:103–143  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

101}
102
103func BenchmarkUnmarshalAsJSON(b *testing.B) {
104 var buf bytes.Buffer
105 enc := NewWriter(&buf)
106 enc.WriteMapHeader(4)
107
108 enc.WriteString("thing_1")
109 enc.WriteString("a string object")
110
111 enc.WriteString("a_first_map")
112 enc.WriteMapHeader(2)
113 enc.WriteString("float_a")
114 enc.WriteFloat32(1.0)
115 enc.WriteString("int_b")
116 enc.WriteInt64(-100)
117
118 enc.WriteString("an array")
119 enc.WriteArrayHeader(2)
120 enc.WriteBool(true)
121 enc.WriteUint(2089)
122
123 enc.WriteString("a_second_map")
124 enc.WriteMapStrStr(map[string]string{
125 "internal_one": "blah",
126 "internal_two": "blahhh...",
127 })
128 enc.Flush()
129
130 var js bytes.Buffer
131 bts := buf.Bytes()
132 _, err := UnmarshalAsJSON(&js, bts)
133 if err != nil {
134 b.Fatal(err)
135 }
136 b.SetBytes(int64(len(js.Bytes())))
137 b.ResetTimer()
138 b.ReportAllocs()
139 for i := 0; i < b.N; i++ {
140 js.Reset()
141 UnmarshalAsJSON(&js, bts)
142 }
143}

Callers

nothing calls this directly

Calls 12

WriteMapHeaderMethod · 0.95
WriteStringMethod · 0.95
WriteFloat32Method · 0.95
WriteInt64Method · 0.95
WriteArrayHeaderMethod · 0.95
WriteBoolMethod · 0.95
WriteUintMethod · 0.95
WriteMapStrStrMethod · 0.95
FlushMethod · 0.95
NewWriterFunction · 0.85
UnmarshalAsJSONFunction · 0.85
ResetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…