aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorEmmanuel T Odeke <emmanuel@orijtech.com>2020-09-24 15:33:45 -0700
committerEmmanuel Odeke <emm.odeke@gmail.com>2020-09-28 20:51:39 +0000
commitc4971a14a7cac78849f4d0908e7140263129bdf7 (patch)
treeef01b9fb90688336334ba98cb4b3dc424a3cafa2 /src/testing
parentf33263d11aa0f5e2668bfc6a0805e4edee17b03c (diff)
downloadgo-c4971a14a7cac78849f4d0908e7140263129bdf7.tar.gz
go-c4971a14a7cac78849f4d0908e7140263129bdf7.zip
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>
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/helper_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/testing/helper_test.go b/src/testing/helper_test.go
index 7ce58c67fb..8858196cf0 100644
--- a/src/testing/helper_test.go
+++ b/src/testing/helper_test.go
@@ -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()
+ }
+ }
+}