github.com/loov/hrtime@v1.0.3/hrtesting/benchmark_nohrtime.go (about) 1 // +build nohrtime 2 3 package hrtesting 4 5 import ( 6 "testing" 7 ) 8 9 // Benchmark implements minimal wrapper over *testing.B for disabling hrtesting. 10 type Benchmark struct { 11 b *testing.B 12 k int 13 } 14 15 // NewBenchmark creates a hrtime.Benchmark wrapper for *testing.B 16 func NewBenchmark(b *testing.B) *Benchmark { 17 return &Benchmark{b: b, k: 0} 18 } 19 20 // Next starts measuring the next lap. 21 // It will return false, when all measurements have been made. 22 func (bench *Benchmark) Next() bool { 23 bench.b.StartTimer() 24 bench.k++ 25 next := bench.k <= bench.b.N 26 if !next { 27 bench.b.StopTimer() 28 } 29 return next 30 } 31 32 // Report reports the result to the console. 33 func (bench *Benchmark) Report() {} 34 35 // Name returns benchmark name. 36 func (bench *Benchmark) Name() string { return bench.b.Name() } 37 38 // Unit returns units it measures. 39 func (bench *Benchmark) Unit() string { return "" } 40 41 // Float64s returns all measurements as float64s 42 func (bench *BenchmarkTSC) Float64s() []float64 { return nil } 43 44 // Benchmark implements minimal wrapper over *testing.B for disabling hrtesting. 45 type BenchmarkTSC = Benchmark 46 47 // NewBenchmark creates a hrtime.BenchmarkTSC wrapper for *testing.B 48 func NewBenchmarkTSC(b *testing.B) *Benchmark { 49 return NewBenchmark(b) 50 }