benchmark

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2021 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package benchmark implements utilities to augment the standard Go testing.Benchmark functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunTestMain

func RunTestMain(m *testing.M) int

RunTestMain runs the tests with enabling injection of benchmark stats. It returns an exit code to pass to os.Exit.

Types

type Stats

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

Stats is a simple helper for gathering additional statistics like histogram during benchmarks. This is not thread safe.

func AddStats

func AddStats(b *testing.B, numBuckets int) *Stats

AddStats adds a new unnamed Stats instance to the current benchmark. You need to run benchmarks by calling RunTestMain() to inject the stats to the benchmark results. If numBuckets is not positive, the default value (16) will be used. Please note that this calls b.ResetTimer() since it may be blocked until the previous benchmark stats is printed out. So AddStats() should typically be called at the very beginning of each benchmark function.

func AddStatsWithName

func AddStatsWithName(b *testing.B, name string, numBuckets int) *Stats

AddStatsWithName adds a new named Stats instance to the current benchmark. With this, you can add multiple stats in a single benchmark. You need to run benchmarks by calling RunTestMain() to inject the stats to the benchmark results. If numBuckets is not positive, the default value (16) will be used. Please note that this calls b.ResetTimer() since it may be blocked until the previous benchmark stats is printed out. So AddStatsWithName() should typically be called at the very beginning of each benchmark function.

func NewStats

func NewStats(numBuckets int) *Stats

NewStats creates a new Stats instance. If numBuckets is not positive, the default value (16) will be used.

func (*Stats) Add

func (stats *Stats) Add(d time.Duration)

Add adds an elapsed time per operation to the stats.

func (*Stats) Clear

func (stats *Stats) Clear()

Clear resets the stats, removing all values.

func (*Stats) Print

func (stats *Stats) Print(w io.Writer)

Print writes textual output of the Stats.

func (*Stats) String

func (stats *Stats) String() string

String returns the textual output of the Stats as string.

Jump to

Keyboard shortcuts

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