+
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions testutil/testorbench.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ type TB interface {

SetBytes(n int64)
N() int

ResetTimer()
StartTimer()
StopTimer()

ReportAllocs()
ReportMetric(n float64, unit string)
}

// tb implements TB as well as testing.TB interfaces.
Expand Down Expand Up @@ -78,8 +84,36 @@ func (t *tb) ResetTimer() {
}
}

// StartTimer starts a timer, if it's a benchmark, noop otherwise.
func (t *tb) StartTimer() {
if b, ok := t.TB.(*testing.B); ok {
b.StartTimer()
}
}

// StopTimer stops a timer, if it's a benchmark, noop otherwise.
func (t *tb) StopTimer() {
if b, ok := t.TB.(*testing.B); ok {
b.StopTimer()
}
}

// IsBenchmark returns true if it's a benchmark.
func (t *tb) IsBenchmark() bool {
_, ok := t.TB.(*testing.B)
return ok
}

// ReportAllocs reports allocs if it's a benchmark, noop otherwise.
func (t *tb) ReportAllocs() {
if b, ok := t.TB.(*testing.B); ok {
b.ReportAllocs()
}
}

// ReportMetric reports metrics if it's a benchmark, noop otherwise.
func (t *tb) ReportMetric(n float64, unit string) {
if b, ok := t.TB.(*testing.B); ok {
b.ReportMetric(n, unit)
}
}
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载