Documentation
¶
Overview ¶
Package hrtesting implements wrappers for testing.B that allow to output more detailed information in standard go benchmarks.
Since, it is mainly built for convenience it needs to call `b.StartTimer` and other benchmark timer functions. As a result, manually calling them can cause unintended measurement results.
Since such benchmarking will have an overhead, it will increase single measurement results. To disable that measurement temporarily "-tags nohrtime".
To use this package write your benchmark as:
func BenchmarkHello(b *testing.B) { bench := hrtesting.NewBenchmark(b) defer bench.Report() for bench.Next() { fmt.Sprintf("hello") } }
Only statements in the `for bench.Next() {` loop will be measured.
To use time stamp counters, which are not supported on all platforms:
func BenchmarkHello(b *testing.B) { bench := hrtesting.NewBenchmarkTSC(b) defer bench.Report() for bench.Next() { fmt.Sprintf("hello") } }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Benchmark ¶
type Benchmark struct {
// contains filtered or unexported fields
}
Benchmark wraps *testing.B to measure more details using hrtime.Benchmark
func NewBenchmark ¶
NewBenchmark creates a new *hrtime.Benchmark using *testing.B parameters.
func (*Benchmark) Next ¶
Next starts measuring the next lap. It will return false, when all measurements have been made.
type BenchmarkTSC ¶
type BenchmarkTSC struct {
// contains filtered or unexported fields
}
BenchmarkTSC wraps *testing.B to measure more details using hrtime.BenchmarkTSC
func NewBenchmarkTSC ¶
func NewBenchmarkTSC(b *testing.B) *BenchmarkTSC
NewBenchmarkTSC creates a new *hrtime.BenchmarkTSC using *testing.B parameters.
func (*BenchmarkTSC) Float64s ¶
func (bench *BenchmarkTSC) Float64s() []float64
Float64s returns all measurements as float64s
func (*BenchmarkTSC) Next ¶
func (bench *BenchmarkTSC) Next() bool
Next starts measuring the next lap. It will return false, when all measurements have been made.
func (*BenchmarkTSC) Report ¶
func (bench *BenchmarkTSC) Report()
Report reports the 50-th, 90-th and 99-th percentile as a metric.
func (*BenchmarkTSC) Unit ¶
func (bench *BenchmarkTSC) Unit() string
Unit returns units it measures.