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

Function BenchmarkDecoderStream

json/golang_bench_test.go:190–213  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

188}
189
190func BenchmarkDecoderStream(b *testing.B) {
191 b.ReportAllocs()
192 b.StopTimer()
193 var buf bytes.Buffer
194 dec := NewDecoder(&buf)
195 buf.WriteString(`"` + strings.Repeat("x", 1000000) + `"` + "\n\n\n")
196 var x any
197 if err := dec.Decode(&x); err != nil {
198 b.Fatal("Decode:", err)
199 }
200 ones := strings.Repeat(" 1\n", 300000) + "\n\n\n"
201 b.StartTimer()
202 for i := range b.N {
203 // XXX: making use of the index variable
204 // is probably a misuse of b.N loops.
205 if i%300000 == 0 {
206 buf.WriteString(ones)
207 }
208 x = nil
209 if err := dec.Decode(&x); err != nil || x != 1.0 {
210 b.Fatalf("Decode: %v after %d", err, i)
211 }
212 }
213}
214
215func BenchmarkCodeUnmarshal(b *testing.B) {
216 b.ReportAllocs()

Callers

nothing calls this directly

Calls 3

DecodeMethod · 0.95
NewDecoderFunction · 0.70
WriteStringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…