hrtesting

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2020 License: MIT Imports: 3 Imported by: 2

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

func NewBenchmark(b *testing.B) *Benchmark

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

func (*Benchmark) Float64s

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

Float64s returns all measurements.

func (*Benchmark) Name

func (bench *Benchmark) Name() string

Name returns benchmark name.

func (*Benchmark) Next

func (bench *Benchmark) Next() bool

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

func (*Benchmark) Report

func (bench *Benchmark) Report()

Report reports the 50-th, 90-th and 99-th percentile as a metric.

func (*Benchmark) Unit

func (bench *Benchmark) Unit() string

Unit returns units it measures.

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) Name

func (bench *BenchmarkTSC) Name() string

Name returns benchmark name.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL