1
0
mirror of https://github.com/golang/go synced 2024-11-26 23:01:23 -07:00

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 <emmanuel@orijtech.com>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
Daniel Martí 2023-04-01 18:44:20 +01:00
parent 311145cf0d
commit 56e900d9f0

View File

@ -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()