bench

package
v0.0.0-...-2f6ede8 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package bench reads and writes Go benchmarks results files.

This format is specified at: https://github.com/golang/proposal/blob/master/design/14313-benchmark-format.md

Index

Constants

This section is empty.

Variables

View Source
var DefaultValueParsers = []ValueParser{
	func(s string) (interface{}, error) { return strconv.Atoi(s) },
	func(s string) (interface{}, error) { return strconv.ParseFloat(s, 64) },
	func(s string) (interface{}, error) { return time.ParseDuration(s) },
}

DefaultValueParsers is the default sequence of value parsers used by ParseValues if no parsers are specified.

Functions

func Fprint

func Fprint(w io.Writer, bs []*Benchmark) error

func ParseValues

func ParseValues(benchmarks []*Benchmark, valueParsers []ValueParser)

ParseValues parses the raw configuration values in benchmarks into structured types using best-effort pattern-based parsing.

If all of the raw values for a given configuration key can be parsed by one of the valueParsers, ParseValues sets the parsed values to the results of that ValueParser. If multiple ValueParsers can parse all of the raw values, it uses the earliest such parser in the valueParsers list.

If valueParsers is nil, it uses DefaultValueParsers.

func Print

func Print(bs []*Benchmark) error

Types

type Benchmark

type Benchmark struct {
	// Name is the name of the benchmark, without the "Benchmark"
	// prefix and without the trailing GOMAXPROCS number.
	Name string

	// Iterations is the number of times this benchmark executed.
	Iterations int

	// Config is the set of configuration pairs for this
	// Benchmark. These can be specified in both configuration
	// blocks and in individual benchmark lines. If the benchmark
	// name is of the form "BenchmarkX-N", the N is stripped out
	// and stored as "gomaxprocs" here.
	Config map[string]*Config

	// Result is the set of (unit, value) metrics for this
	// benchmark run.
	Result map[string]float64
}

Benchmark records the configuration and results of a single benchmark run (a single line of a benchmark results file).

func Parse

func Parse(r io.Reader) ([]*Benchmark, error)

Parse parses a standard Go benchmark results file from r. It returns a *Benchmark for each benchmark result line in the file. There may be many result lines for the same benchmark name and configuration, indicating that the benchmark was run multiple times.

In the returned Benchmarks, RawValue is set, but Value is always nil. Use ParseValues to convert raw values to structured types.

type Config

type Config struct {
	// Value is the parsed value of this configuration value.
	Value interface{}

	// RawValue is the value of this configuration value, exactly
	// as written in the original benchmark file.
	RawValue string

	// InBlock indicates that this configuration value was
	// specified in a configuration block line. Otherwise, it was
	// specified in the benchmark line.
	InBlock bool
}

Config represents a single key/value configuration pair.

type ValueParser

type ValueParser func(string) (interface{}, error)

ValueParser is a function that parses a string value into a structured type or returns an error if the string cannot be parsed.

Jump to

Keyboard shortcuts

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