From 56e900d9f0da967d9152c546db1684653a69ece5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Mart=C3=AD?= Date: Sat, 1 Apr 2023 18:44:20 +0100 Subject: [PATCH] encoding/gob: report allocs in benchmarks MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 --- src/encoding/gob/timing_test.go | 4 ++++ 1 file changed, 4 insertions(+) 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() -- 2.50.0