Skip to content

Commit cb66462

Browse files
committed
encoding/json: use SetBytes in UnmarshalReuse benchmark
This was the only benchmark missing the SetBytes call, as spotted earlier by Bryan. It's not required to make the benchmark useful, but it can still be a good way to see how its speed is affected by the reduced allocations: name time/op CodeUnmarshal-8 12.1ms ± 1% CodeUnmarshalReuse-8 11.4ms ± 1% name speed CodeUnmarshal-8 161MB/s ± 1% CodeUnmarshalReuse-8 171MB/s ± 1% name alloc/op CodeUnmarshal-8 3.28MB ± 0% CodeUnmarshalReuse-8 1.94MB ± 0% name allocs/op CodeUnmarshal-8 92.7k ± 0% CodeUnmarshalReuse-8 77.6k ± 0% While at it, remove some unnecessary empty lines. Change-Id: Ib2bd92d5b3237b8f3092e8c6f863dab548fee2f5 Reviewed-on: https://go-review.googlesource.com/c/go/+/170938 Run-TryBot: Daniel Martí <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 06cff11 commit cb66462

File tree

3 files changed

+1
-4
lines changed

3 files changed

+1
-4
lines changed

src/encoding/json/bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ func BenchmarkCodeUnmarshalReuse(b *testing.B) {
242242
}
243243
}
244244
})
245-
// TODO(bcmills): Is there a missing b.SetBytes here?
245+
b.SetBytes(int64(len(codeJSON)))
246246
}
247247

248248
func BenchmarkUnmarshalString(b *testing.B) {

src/encoding/json/example_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ func ExampleDecoder_Decode_stream() {
170170
// Sam: Go fmt who?
171171
// Ed: Go fmt yourself!
172172
// json.Delim: ]
173-
174173
}
175174

176175
// This example uses RawMessage to delay parsing part of a JSON message.

src/encoding/json/stream_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ var tokenStreamCases = []tokenStreamCase{
368368
}
369369

370370
func TestDecodeInStream(t *testing.T) {
371-
372371
for ci, tcase := range tokenStreamCases {
373372

374373
dec := NewDecoder(strings.NewReader(tcase.json))
@@ -401,7 +400,6 @@ func TestDecodeInStream(t *testing.T) {
401400
}
402401
}
403402
}
404-
405403
}
406404

407405
// Test from golang.org/issue/11893

0 commit comments

Comments
 (0)