1
0
mirror of https://github.com/golang/go synced 2024-11-17 14:54:44 -07:00

testing: add benchmark for TB.Helper

Adds a benchmark for TB.Helper, to use as a judge of future
improvements like CL 231717.

Change-Id: I17c40d482fc12caa3eb2c1cda39fd8c42356b422
Reviewed-on: https://go-review.googlesource.com/c/go/+/257317
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Trust: Emmanuel Odeke <emm.odeke@gmail.com>
This commit is contained in:
Emmanuel T Odeke 2020-09-24 15:33:45 -07:00 committed by Emmanuel Odeke
parent f33263d11a
commit c4971a14a7

View File

@ -70,3 +70,34 @@ func TestTBHelperParallel(t *T) {
t.Errorf("got output line %q; want %q", got, want)
}
}
type noopWriter int
func (nw *noopWriter) Write(b []byte) (int, error) { return len(b), nil }
func BenchmarkTBHelper(b *B) {
w := noopWriter(0)
ctx := newTestContext(1, newMatcher(regexp.MatchString, "", ""))
t1 := &T{
common: common{
signal: make(chan bool),
w: &w,
},
context: ctx,
}
f1 := func() {
t1.Helper()
}
f2 := func() {
t1.Helper()
}
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if i&1 == 0 {
f1()
} else {
f2()
}
}
}