]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/gob: report allocs in benchmarks
authorDaniel Martí <mvdan@mvdan.cc>
Sat, 1 Apr 2023 17:44:20 +0000 (18:44 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Tue, 4 Apr 2023 07:16:59 +0000 (07:16 +0000)
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>
src/encoding/gob/timing_test.go

index bdee39c447d5d981253161c7e30ab7d54986d568..84349fb179b87276e914d4a6c0be52c9ed1c869d 100644 (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()