hrtime: github.com/loov/hrtime/hrtesting Index | Files

package hrtesting

import "github.com/loov/hrtime/hrtesting"

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

Package Files

benchmark.go benchmark_old.go doc.go

type Benchmark Uses

type Benchmark struct {
    // contains filtered or unexported fields
}

Benchmark wraps *testing.B to measure more details using hrtime.Benchmark

func NewBenchmark Uses

func NewBenchmark(b *testing.B) *Benchmark

NewBenchmark creates a new *hrtime.Benchmark using *testing.B parameters.

func (*Benchmark) Float64s Uses

func (bench *Benchmark) Float64s() []float64

Float64s returns all measurements.

func (*Benchmark) Name Uses

func (bench *Benchmark) Name() string

Name returns benchmark name.

func (*Benchmark) Next Uses

func (bench *Benchmark) Next() bool

Next starts measuring the next lap. It will return false, when all measurements have been made.

func (*Benchmark) Report Uses

func (bench *Benchmark) Report()

Report reports the 50-th, 90-th and 99-th percentile to the log.

func (*Benchmark) Unit Uses

func (bench *Benchmark) Unit() string

Unit returns units it measures.

type BenchmarkTSC Uses

type BenchmarkTSC struct {
    // contains filtered or unexported fields
}

BenchmarkTSC wraps *testing.B to measure more details using hrtime.BenchmarkTSC

func NewBenchmarkTSC Uses

func NewBenchmarkTSC(b *testing.B) *BenchmarkTSC

NewBenchmarkTSC creates a new *hrtime.BenchmarkTSC using *testing.B parameters.

func (*BenchmarkTSC) Float64s Uses

func (bench *BenchmarkTSC) Float64s() []float64

Float64s returns all measurements as float64s

func (*BenchmarkTSC) Name Uses

func (bench *BenchmarkTSC) Name() string

Name returns benchmark name.

func (*BenchmarkTSC) Next Uses

func (bench *BenchmarkTSC) Next() bool

Next starts measuring the next lap. It will return false, when all measurements have been made.

func (*BenchmarkTSC) Report Uses

func (bench *BenchmarkTSC) Report()

Report reports the 50-th, 90-th and 99-th percentile to the log.

func (*BenchmarkTSC) Unit Uses

func (bench *BenchmarkTSC) Unit() string

Unit returns units it measures.

Package hrtesting imports 4 packages (graph). Updated 2019-04-15. Refresh now. Tools for package owners.