Commit 6a6f4a46 authored by Travis Bischel's avatar Travis Bischel Committed by Brad Fitzpatrick

net/textproto: redo BenchmarkReadMIMEHeader

This benchmark is odd currently because it uses inconsistent cases
between benchmark iterations, and each iteration actually does a bit of
testing.

This separates the two benchmark cases into two separate benchmarks and
removes the testing done on each iteration. The unit tests above
suffice.

The benchmark being more succinct will make it easier to gauge the
benefits of any future MIME header reading changes.

Change-Id: I2399fab28067f1aeec3d9b16951d39d787f8b39c
Reviewed-on: https://go-review.googlesource.com/134225Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 06afc8b1
......@@ -382,31 +382,25 @@ Non-Interned: test
func BenchmarkReadMIMEHeader(b *testing.B) {
b.ReportAllocs()
var buf bytes.Buffer
br := bufio.NewReader(&buf)
r := NewReader(br)
for i := 0; i < b.N; i++ {
var want int
var find string
if (i & 1) == 1 {
buf.WriteString(clientHeaders)
want = 10
find = "Cookie"
} else {
buf.WriteString(serverHeaders)
want = 9
find = "Via"
}
h, err := r.ReadMIMEHeader()
if err != nil {
b.Fatal(err)
}
if len(h) != want {
b.Fatalf("wrong number of headers: got %d, want %d", len(h), want)
}
if _, ok := h[find]; !ok {
b.Fatalf("did not find key %s", find)
}
for _, set := range []struct {
name string
headers string
}{
{"client_headers", clientHeaders},
{"server_headers", serverHeaders},
} {
b.Run(set.name, func(b *testing.B) {
var buf bytes.Buffer
br := bufio.NewReader(&buf)
r := NewReader(br)
for i := 0; i < b.N; i++ {
buf.WriteString(set.headers)
if _, err := r.ReadMIMEHeader(); err != nil {
b.Fatal(err)
}
}
})
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment