benchutil

package module
v0.0.0-...-3392ed7 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2017 License: MIT Imports: 18 Imported by: 29

README

benchutil

GoDocBuild Status

Helper library to generate formatted output from testing.BenchmarkResult data.

Supported formats:

  • text (default)
  • CSV
  • Markdown; results are formatted as a table

Benchmark results can be labeled by providing a name. Additional information for the benchmark can be added through the description and notes fields. Related benchmarks can be labeled by providing a group (grouping of groups is not done, the output is in the same order as they were added.)

Groups can be separated out to their own sections. For markdown output, these sections can be created as their own table, and, optionally, the table can use the group identifier as its label, which results in the group column being omitted from the table.

Documentation

Overview

Package benchutil contains utilities used for benchmarking and

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dot

func Dot(done chan struct{})

Dot prints a . every second to os.StdOut.

func NewSeed

func NewSeed() int64

NewSeed gets a random int64 to use for a seed value.

func RandBool

func RandBool() bool

RandBool returns a pseudo-random bool value.

func RandBytes

func RandBytes(l uint32) []byte

RandBytes returns a randomly generated []byte of length l. The values of these bytes are restricted to the ASCII alphanum range; that doesn't matter for the purposes of these benchmarks.

func RandString

func RandString(l uint32) string

RandString returns a randomly generated string of length l.

Types

type Bench

type Bench struct {
	Group      string // the Grouping of benchmarks this bench belongs to.
	SubGroup   string // the Sub-Group this bench belongs to; mainly for additional sort options.
	Name       string // Name of the bench.
	Desc       string // Description of the bench; optional.
	Note       string // Additional note about the bench; optional.
	Iterations int    // number of test iterations; default 1
	Result            // A map of Result keyed by something.
}

Bench holds information about a benchmark. If there is a value for Group, the output will have a break between the groups.

func NewBench

func NewBench(s string) Bench

type Benches

type Benches struct {
	Name       string  // Name of the set; optional.
	Desc       string  // Description of the collection of benchmarks; optional.
	Note       string  // Additional notes about the set; optional.
	Benchmarks []Bench // The benchmark results
	// contains filtered or unexported fields
}

Benches is a collection of benchmark informtion and their results.

func (*Benches) AllocsOpString

func (b *Benches) AllocsOpString(v Bench) string

AllocsOpString returns the allocations per operation as a formatted string.

func (*Benches) Append

func (b *Benches) Append(benches ...Bench)

Add adds a Bench to the slice of Benchmarks

func (*Benches) BytesOpString

func (b *Benches) BytesOpString(v Bench) string

BytesOpString returns the bytes allocated for each operation as a formatted string.

func (*Benches) DetailedSystemInfo

func (b *Benches) DetailedSystemInfo() (string, error)

DetailedSystemInfo generates the System Information string, including information about every CPU core on the system.

func (*Benches) IncludeDetailedSystemInfo

func (b *Benches) IncludeDetailedSystemInfo(v bool)

DetailedSystemInfoOutput: if true, detailed system info will be included in the benchmarker's output. If both IncludeSystemInfo and IncludeDetailedSystemInfo are set to true, the detailed system info will be included.

func (*Benches) IncludeOpsColumnDesc

func (b *Benches) IncludeOpsColumnDesc(v bool)

IncludeOpsColumnDesc: if true, the ops information will be included in each ops column's result.

func (*Benches) IncludeSystemInfo

func (b *Benches) IncludeSystemInfo(v bool)

IncludeSystemInfo: if true, basic system info will be included in the benchmarker's output. If both IncludeSystemInfo and IncludeDetailedSystemInfo are set to true, the detailed system info will be included.

func (*Benches) NameSections

func (b *Benches) NameSections(v bool)

Sets the nameSections bool. Txt output ignores this.

func (*Benches) NsOpString

func (b *Benches) NsOpString(v Bench) string

NsOpString returns the nanoseconds each operation took as a formatted string.

func (*Benches) OpsString

func (b *Benches) OpsString(v Bench) string

OpsString returns the operations performed by the benchmark as a formatted string.

func (*Benches) SectionHeaders

func (b *Benches) SectionHeaders(v bool)

Sets the sectionHeaders bool. Txt output ignores this.

func (*Benches) SectionPerGroup

func (b *Benches) SectionPerGroup(v bool)

Sets the sectionPerGroup bool

func (*Benches) SetAllocsOpColumnHeader

func (h *Benches) SetAllocsOpColumnHeader(s string)

SetAllocsOpColumnHeader sets the AllocsOp column header; default is 'Allocs/Op'. This only applies when AllocsOp is part of the output.

func (*Benches) SetBytesOpColumnHeader

func (h *Benches) SetBytesOpColumnHeader(s string)

SetBytesOpColumnHeader sets the BytesOp column header; default is 'B/Op'. This only applies when BytesOp is part of the output.

func (*Benches) SetColumnPadding

func (b *Benches) SetColumnPadding(i int)

Sets the number of spaces between columns; default is 2.

func (*Benches) SetDescColumnHeader

func (h *Benches) SetDescColumnHeader(s string)

SetDescColumnHeader sets the Desc column header; default is 'Desc'. This only applies when Desc is part of the output.

func (*Benches) SetGroupColumnHeader

func (h *Benches) SetGroupColumnHeader(s string)

SetGroupColumnHeader sets the Group column header; default is 'Group'. This only applies when Group is part of the output.

func (*Benches) SetNameColumnHeader

func (h *Benches) SetNameColumnHeader(s string)

SetNameColumnHeader sets the Name column header; default is 'Name'.

func (*Benches) SetNoteColumnHeader

func (h *Benches) SetNoteColumnHeader(s string)

SetNoteColumnHeader sets the Note column header; default is 'Note'. This only applies when Note is part of the output.

func (*Benches) SetNsOpColumnHeader

func (h *Benches) SetNsOpColumnHeader(s string)

SetNsOpColumnHeader sets the NsOp column header; default is 'ns/Op'. This only applies when NsOp is part of the output.

func (*Benches) SetOpsColumnHeader

func (h *Benches) SetOpsColumnHeader(s string)

SetOpsColumnHeader sets the Ops column header; default is 'Ops'. This only applies when Ops is part of the output.

func (*Benches) SetSubGroupColumnHeader

func (h *Benches) SetSubGroupColumnHeader(s string)

SetSubGroupColumnHeader sets the SubGroup column header; default is 'Sub-Group'. This only applies when SubGroup is part of the output.

func (*Benches) SystemInfo

func (b *Benches) SystemInfo() (string, error)

SystemInfo generates a System Information string.

type Benchmarker

type Benchmarker interface {
	Append(...Bench)
	Out() error
	IncludeOpsColumnDesc(bool)
	IncludeSystemInfo(bool)
	IncludeDetailedSystemInfo(bool)
	SystemInfo() (string, error)
	DetailedSystemInfo() (string, error)
	SetGroupColumnHeader(s string)
	SetSubGroupColumnHeader(s string)
	SetNameColumnHeader(s string)
	SetDescColumnHeader(s string)
	SetOpsColumnHeader(s string)
	SetNsOpColumnHeader(s string)
	SetBytesOpColumnHeader(s string)
	SetAllocsOpColumnHeader(s string)
	SetNoteColumnHeader(s string)
	SetColumnPadding(i int)
	SectionPerGroup(bool)
	SectionHeaders(bool)
	NameSections(bool)
}

Benchmarker defines common behavior for a Benchmark output harness; format specific methods may be

type CSVBench

type CSVBench struct {
	Benches
	// contains filtered or unexported fields
}

CSVBench Benches is a collection of benchmark informtion and their results. The output is written as CSV to the writer. The Name, Desc, and Note fields are ignored

func NewCSVBench

func NewCSVBench(w io.Writer) *CSVBench

func (*CSVBench) Out

func (b *CSVBench) Out() error

Out writes the benchmark results to the writer as strings.

func (*CSVBench) SetAllocsOpColumnHeader

func (h *CSVBench) SetAllocsOpColumnHeader(s string)

SetAllocsOpColumnHeader sets the AllocsOp column header; default is 'Allocs/Op'. This only applies when AllocsOp is part of the output.

func (*CSVBench) SetBytesOpColumnHeader

func (h *CSVBench) SetBytesOpColumnHeader(s string)

SetBytesOpColumnHeader sets the BytesOp column header; default is 'B/Op'. This only applies when BytesOp is part of the output.

func (*CSVBench) SetDescColumnHeader

func (h *CSVBench) SetDescColumnHeader(s string)

SetDescColumnHeader sets the Desc column header; default is 'Desc'. This only applies when Desc is part of the output.

func (*CSVBench) SetGroupColumnHeader

func (h *CSVBench) SetGroupColumnHeader(s string)

SetGroupColumnHeader sets the Group column header; default is 'Group'. This only applies when Group is part of the output.

func (*CSVBench) SetNameColumnHeader

func (h *CSVBench) SetNameColumnHeader(s string)

SetNameColumnHeader sets the Name column header; default is 'Name'.

func (*CSVBench) SetNoteColumnHeader

func (h *CSVBench) SetNoteColumnHeader(s string)

SetNoteColumnHeader sets the Note column header; default is 'Note'. This only applies when Note is part of the output.

func (*CSVBench) SetNsOpColumnHeader

func (h *CSVBench) SetNsOpColumnHeader(s string)

SetNsOpColumnHeader sets the NsOp column header; default is 'ns/Op'. This only applies when NsOp is part of the output.

func (*CSVBench) SetOpsColumnHeader

func (h *CSVBench) SetOpsColumnHeader(s string)

SetOpsColumnHeader sets the Ops column header; default is 'Ops'. This only applies when Ops is part of the output.

func (*CSVBench) SetSubGroupColumnHeader

func (h *CSVBench) SetSubGroupColumnHeader(s string)

SetSubGroupColumnHeader sets the SubGroup column header; default is 'Sub-Group'. This only applies when SubGroup is part of the output.

type MDBench

type MDBench struct {
	Benches

	SectionHeaderHash string // the markdown header hash for section names, when applicable
	// contains filtered or unexported fields
}

MDBench Benches is a collection of benchmark informtion and their results. The output is written as Markdown to the writer, with the benchmark results formatted as a table.

func NewMDBench

func NewMDBench(w io.Writer) *MDBench

func (*MDBench) Out

func (b *MDBench) Out() error

Out writes the benchmark results to the writer as a Markdown Table.

func (*MDBench) SectionName

func (b *MDBench) SectionName(s string) string

SectionName generates the section name; if applicable.

func (*MDBench) SetAllocsOpColumnHeader

func (h *MDBench) SetAllocsOpColumnHeader(s string)

SetAllocsOpColumnHeader sets the AllocsOp column header; default is 'Allocs/Op'. This only applies when AllocsOp is part of the output.

func (*MDBench) SetBytesOpColumnHeader

func (h *MDBench) SetBytesOpColumnHeader(s string)

SetBytesOpColumnHeader sets the BytesOp column header; default is 'B/Op'. This only applies when BytesOp is part of the output.

func (*MDBench) SetDescColumnHeader

func (h *MDBench) SetDescColumnHeader(s string)

SetDescColumnHeader sets the Desc column header; default is 'Desc'. This only applies when Desc is part of the output.

func (*MDBench) SetGroupColumnHeader

func (h *MDBench) SetGroupColumnHeader(s string)

SetGroupColumnHeader sets the Group column header; default is 'Group'. This only applies when Group is part of the output.

func (*MDBench) SetNameColumnHeader

func (h *MDBench) SetNameColumnHeader(s string)

SetNameColumnHeader sets the Name column header; default is 'Name'.

func (*MDBench) SetNoteColumnHeader

func (h *MDBench) SetNoteColumnHeader(s string)

SetNoteColumnHeader sets the Note column header; default is 'Note'. This only applies when Note is part of the output.

func (*MDBench) SetNsOpColumnHeader

func (h *MDBench) SetNsOpColumnHeader(s string)

SetNsOpColumnHeader sets the NsOp column header; default is 'ns/Op'. This only applies when NsOp is part of the output.

func (*MDBench) SetOpsColumnHeader

func (h *MDBench) SetOpsColumnHeader(s string)

SetOpsColumnHeader sets the Ops column header; default is 'Ops'. This only applies when Ops is part of the output.

func (*MDBench) SetSubGroupColumnHeader

func (h *MDBench) SetSubGroupColumnHeader(s string)

SetSubGroupColumnHeader sets the SubGroup column header; default is 'Sub-Group'. This only applies when SubGroup is part of the output.

type Result

type Result struct {
	Ops      int64 // the number of operations performed
	NsOp     int64 // The amount of time, in Nanoseconds, per Op.
	BytesOp  int64 // The number of bytes allocated per Op.
	AllocsOp int64 // The number of Allocations per Op.
}

Result holds information about a benchmark's results.

func ResultFromBenchmarkResult

func ResultFromBenchmarkResult(br testing.BenchmarkResult) Result

ResultFromBenchmarkResult creates a Result{} from a testing.BenchmarkResult.

type StringBench

type StringBench struct {
	Benches
	// contains filtered or unexported fields
}

StringBench generates string output from the benchmarks.

func NewStringBench

func NewStringBench(w io.Writer) *StringBench

func (*StringBench) BenchString

func (b *StringBench) BenchString(i int) string

BenchString generates the Ops, ns/Ops, B/Ops, and Allocs/Op string for a given benchmark result.

func (*StringBench) Out

func (b *StringBench) Out() error

Out writes the benchmark results.

func (*StringBench) SetAllocsOpColumnHeader

func (h *StringBench) SetAllocsOpColumnHeader(s string)

SetAllocsOpColumnHeader sets the AllocsOp column header; default is 'Allocs/Op'. This only applies when AllocsOp is part of the output.

func (*StringBench) SetBytesOpColumnHeader

func (h *StringBench) SetBytesOpColumnHeader(s string)

SetBytesOpColumnHeader sets the BytesOp column header; default is 'B/Op'. This only applies when BytesOp is part of the output.

func (*StringBench) SetDescColumnHeader

func (h *StringBench) SetDescColumnHeader(s string)

SetDescColumnHeader sets the Desc column header; default is 'Desc'. This only applies when Desc is part of the output.

func (*StringBench) SetGroupColumnHeader

func (h *StringBench) SetGroupColumnHeader(s string)

SetGroupColumnHeader sets the Group column header; default is 'Group'. This only applies when Group is part of the output.

func (*StringBench) SetNameColumnHeader

func (h *StringBench) SetNameColumnHeader(s string)

SetNameColumnHeader sets the Name column header; default is 'Name'.

func (*StringBench) SetNoteColumnHeader

func (h *StringBench) SetNoteColumnHeader(s string)

SetNoteColumnHeader sets the Note column header; default is 'Note'. This only applies when Note is part of the output.

func (*StringBench) SetNsOpColumnHeader

func (h *StringBench) SetNsOpColumnHeader(s string)

SetNsOpColumnHeader sets the NsOp column header; default is 'ns/Op'. This only applies when NsOp is part of the output.

func (*StringBench) SetOpsColumnHeader

func (h *StringBench) SetOpsColumnHeader(s string)

SetOpsColumnHeader sets the Ops column header; default is 'Ops'. This only applies when Ops is part of the output.

func (*StringBench) SetSubGroupColumnHeader

func (h *StringBench) SetSubGroupColumnHeader(s string)

SetSubGroupColumnHeader sets the SubGroup column header; default is 'Sub-Group'. This only applies when SubGroup is part of the output.

func (*StringBench) WriteHeader

func (b *StringBench) WriteHeader()

WriteHeader writes the table header to the writer.

func (*StringBench) WriteResults

func (b *StringBench) WriteResults()

WriteResults writes the benchmark results to the writer.

func (*StringBench) WriteSeparatorLine

func (b *StringBench) WriteSeparatorLine()

WriteSeparatorLine writes a line consisting of dashes to the writer.

Jump to

Keyboard shortcuts

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