bench

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package bench parse Golang standard benchmark output

@update 2023-03-07 12:06:22

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Baseline added in v0.2.0

func Baseline(sets []Set, baselines []float64)

Baseline compare benchmark result with baseline

@param sets []Set
@param baselines []float64
@return []Set
@author kevineluo
@update 2023-04-18 04:14:32

Types

type Benchmark

type Benchmark struct {
	Name     string `json:"name,omitempty"`
	CPUCores int    `json:"cpu_cores,omitempty"`
	Runs     int    `json:"runs,omitempty"` // benchmark times

	// For a Benchmark function BenchXXX10000, its target is XXX, and its Scenario is 10000
	// The Benchmark of different target is compared in each Scenario
	Target   string `json:"target,omitempty"`
	Scenario string `json:"scenario,omitempty"`

	NsPerOp       float64            `json:"ns_per_op,omitempty"`
	Mem           Mem                `json:"mem,omitempty"`            // metrics from '-benchmem'
	CustomMetrics map[string]float64 `json:"custom_metrics,omitempty"` // custom metrics(https://tip.golang.org/pkg/testing/#B.ReportMetric)

	ReachBaseline bool `json:"reach_baseline"` // whether this benchmark reach baseline
}

Benchmark is an individual run. Note that all metrics in here must be represented as a float type, even if Go only emits integer values, so that in checks we can correctly evaluate divisions so that results come out as floats instead of being truncated to integers.

func ParseBench

func ParseBench(line string, sep string, regex *regexp2.Regexp) (bench *Benchmark, err error)

ParseBench parses a single line from a benchmark.

Benchmarks take the following format:

BenchmarkXXX	300000	5160 ns/op	5408 B/op	69 allocs/op
@param line string
@return bench *Benchmark
@return err error
@author kevineluo
@update 2023-03-07 12:11:18

type BenchmarkList

type BenchmarkList []Benchmark

BenchmarkList implement sort.Interface

@author kevineluo
@update 2023-03-07 03:21:11

func (BenchmarkList) Len

func (b BenchmarkList) Len() int

func (BenchmarkList) Less

func (b BenchmarkList) Less(i, j int) bool

func (BenchmarkList) Swap

func (b BenchmarkList) Swap(i, j int)

type Mem

type Mem struct {
	BytesPerOp  float64 `json:"bytes_per_op,omitempty"`
	AllocsPerOp float64 `json:"allocs_per_op,omitempty"`
	MBPerSec    float64 `json:"mb_per_sec,omitempty"`
}

Mem is memory allocation information about a run

type Set

type Set struct {
	Goos    string                   `json:"goos,omitempty"`
	Goarch  string                   `json:"goarch,omitempty"`
	Pkg     string                   `json:"pkg,omitempty"`
	CPU     string                   `json:"cpu,omitempty"`
	Targets map[string]BenchmarkList `json:"targets,omitempty"` // map[target][]Benchmark; group of Benchmark result(Series in visualized result)
}

Set is a set of benchmark runs

func Parse

func Parse(reader *bufio.Reader, sep string, regex *regexp2.Regexp) ([]Set, error)

Parse parse Golang standard benchmark output

@param reader *bufio.Reader
@param sep string sep of a Benchmark string's target and scenario
@return []Set Sets of structured benchmark
@return error
@author kevineluo
@update 2023-03-07 01:29:47

func ParseSet

func ParseSet(reader *bufio.Reader, sep string, regex *regexp2.Regexp) (set *Set, err error)

ParseSet Parse one set of benchmark output

@param reader LineReader
@param firstLine string
@param groupRegexps ...*regexp2.Regexp regexps for identify group of benchmark
@return set *Set
@return err error
@author kevineluo
@update 2023-03-07 12:16:30

func (*Set) GetScenarios added in v0.1.4

func (set *Set) GetScenarios() (scenarios []string)

GetScenarios get all unique scenario in a Benchmark set

@receiver set *Set
@return scenarios []string
@author kevineluo
@update 2023-03-07 04:33:12

Jump to

Keyboard shortcuts

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