@@ -30,7 +30,13 @@ type TB interface {
30
30
31
31
SetBytes (n int64 )
32
32
N () int
33
+
33
34
ResetTimer ()
35
+ StartTimer ()
36
+ StopTimer ()
37
+
38
+ ReportAllocs ()
39
+ ReportMetric (n float64 , unit string )
34
40
}
35
41
36
42
// tb implements TB as well as testing.TB interfaces.
@@ -78,8 +84,36 @@ func (t *tb) ResetTimer() {
78
84
}
79
85
}
80
86
87
+ // StartTimer starts a timer, if it's a benchmark, noop otherwise.
88
+ func (t * tb ) StartTimer () {
89
+ if b , ok := t .TB .(* testing.B ); ok {
90
+ b .StartTimer ()
91
+ }
92
+ }
93
+
94
+ // StopTimer stops a timer, if it's a benchmark, noop otherwise.
95
+ func (t * tb ) StopTimer () {
96
+ if b , ok := t .TB .(* testing.B ); ok {
97
+ b .StopTimer ()
98
+ }
99
+ }
100
+
81
101
// IsBenchmark returns true if it's a benchmark.
82
102
func (t * tb ) IsBenchmark () bool {
83
103
_ , ok := t .TB .(* testing.B )
84
104
return ok
85
105
}
106
+
107
+ // ReportAllocs reports allocs if it's a benchmark, noop otherwise.
108
+ func (t * tb ) ReportAllocs () {
109
+ if b , ok := t .TB .(* testing.B ); ok {
110
+ b .ReportAllocs ()
111
+ }
112
+ }
113
+
114
+ // ReportMetric reports metrics if it's a benchmark, noop otherwise.
115
+ func (t * tb ) ReportMetric (n float64 , unit string ) {
116
+ if b , ok := t .TB .(* testing.B ); ok {
117
+ b .ReportMetric (n , unit )
118
+ }
119
+ }
0 commit comments