]> Cypherpunks repositories - gostls13.git/commitdiff
testing: add benchmark for TB.Helper
authorEmmanuel T Odeke <emmanuel@orijtech.com>
Thu, 24 Sep 2020 22:33:45 +0000 (15:33 -0700)
committerEmmanuel Odeke <emm.odeke@gmail.com>
Mon, 28 Sep 2020 20:51:39 +0000 (20:51 +0000)
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>

src/testing/helper_test.go

index 7ce58c67fbc34c6b17e81023142f3af4874bfa3e..8858196cf08c9e2e5c7e1661c70da85fae3f3f4a 100644 (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()
+               }
+       }
+}