From: Daniel Martí Date: Sat, 1 Apr 2023 17:44:20 +0000 (+0100) Subject: encoding/gob: report allocs in benchmarks X-Git-Tag: go1.21rc1~1056 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=56e900d9f0da967d9152c546db1684653a69ece5;p=gostls13.git encoding/gob: report allocs in benchmarks I almost exclusively use these benchmarks with -benchtime already. Change-Id: I6539cbba6abbdb6b275502e122f4e16856d8b9e4 Reviewed-on: https://go-review.googlesource.com/c/go/+/481375 Reviewed-by: Emmanuel Odeke Run-TryBot: Daniel Martí TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor Reviewed-by: Michael Knyszek Reviewed-by: Rob Pike --- diff --git a/src/encoding/gob/timing_test.go b/src/encoding/gob/timing_test.go index bdee39c447..84349fb179 100644 --- a/src/encoding/gob/timing_test.go +++ b/src/encoding/gob/timing_test.go @@ -21,6 +21,7 @@ type Bench struct { } func benchmarkEndToEnd(b *testing.B, ctor func() any, pipe func() (r io.Reader, w io.Writer, err error)) { + b.ReportAllocs() b.RunParallel(func(pb *testing.PB) { r, w, err := pipe() if err != nil { @@ -135,6 +136,7 @@ func TestCountDecodeMallocs(t *testing.T) { func benchmarkEncodeSlice(b *testing.B, a any) { b.ResetTimer() + b.ReportAllocs() b.RunParallel(func(pb *testing.PB) { var buf bytes.Buffer enc := NewEncoder(&buf) @@ -229,6 +231,7 @@ func benchmarkDecodeSlice(b *testing.B, a any) { rt := ra.Type() b.ResetTimer() + b.ReportAllocs() b.RunParallel(func(pb *testing.PB) { // TODO(#19025): Move per-thread allocation before ResetTimer. rp := reflect.New(rt) @@ -316,6 +319,7 @@ func BenchmarkDecodeMap(b *testing.B) { } bbuf := benchmarkBuf{data: buf.Bytes()} b.ResetTimer() + b.ReportAllocs() for i := 0; i < b.N; i++ { var rm map[int]int bbuf.reset()