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

Function BenchmarkCopyToJSON

msgp/json_test.go:130–170  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

128}
129
130func BenchmarkCopyToJSON(b *testing.B) {
131 var buf bytes.Buffer
132 enc := NewWriter(&buf)
133 enc.WriteMapHeader(4)
134
135 enc.WriteString("thing_1")
136 enc.WriteString("a string object")
137
138 enc.WriteString("a_first_map")
139 enc.WriteMapHeader(2)
140 enc.WriteString("float_a")
141 enc.WriteFloat32(1.0)
142 enc.WriteString("int_b")
143 enc.WriteInt64(-100)
144
145 enc.WriteString("an array")
146 enc.WriteArrayHeader(2)
147 enc.WriteBool(true)
148 enc.WriteUint(2089)
149
150 enc.WriteString("a_second_map")
151 enc.WriteMapStrStr(map[string]string{
152 "internal_one": "blah",
153 "internal_two": "blahhh...",
154 })
155 enc.Flush()
156
157 var js bytes.Buffer
158 bts := buf.Bytes()
159 _, err := CopyToJSON(&js, &buf)
160 if err != nil {
161 b.Fatal(err)
162 }
163 b.SetBytes(int64(len(js.Bytes())))
164 b.ResetTimer()
165 b.ReportAllocs()
166 for i := 0; i < b.N; i++ {
167 js.Reset()
168 CopyToJSON(&js, bytes.NewReader(bts))
169 }
170}
171
172func BenchmarkStdlibJSON(b *testing.B) {
173 obj := map[string]any{

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
CopyToJSONFunction · 0.85
ResetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…