(b *testing.B)
| 128 | } |
| 129 | |
| 130 | func 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 | |
| 172 | func BenchmarkStdlibJSON(b *testing.B) { |
| 173 | obj := map[string]any{ |
nothing calls this directly
no test coverage detected
searching dependent graphs…