benchcmp

package
v1.0.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package benchcmp compares Go benchmark output without applying pass/fail thresholds.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Median

func Median(values []float64) (float64, error)

Median returns the median of values without changing their order.

func ValidateCompleteness

func ValidateCompleteness(results Results, expectedBenchmarks int, expectedSamples int) error

ValidateCompleteness checks that a benchmark run contains the expected number of benchmarks and observations for every reported metric. A zero expectation disables that dimension.

func ValidateExpectedNames

func ValidateExpectedNames(results Results, expected []string) error

ValidateExpectedNames checks that results contain exactly the normalized benchmark names in expected. An empty expected manifest disables the check.

func WriteMarkdown

func WriteMarkdown(
	w io.Writer,
	baseline Results,
	candidate Results,
	baselineLabel string,
	candidateLabel string,
) error

WriteMarkdown writes a deterministic comparison table. Ratios are candidate divided by baseline; the function deliberately makes no threshold or pass/fail decision.

Types

type Distribution

type Distribution struct {
	Count  int
	First  float64
	Median float64
	Third  float64
}

Distribution summarizes one metric without hiding its observation count or middle-half spread.

func Summarize

func Summarize(values []float64) (Distribution, error)

Summarize returns the sample count, median, and linearly interpolated first and third quartiles without changing the input order.

type Metric

type Metric string

Metric identifies one of the standard Go benchmark metrics compared by this package.

const (
	MetricNanosecondsPerOperation Metric = "ns/op"
	MetricBytesPerOperation       Metric = "B/op"
	MetricAllocationsPerOperation Metric = "allocs/op"
)

type Results

type Results map[string]Samples

Results maps normalized benchmark names to their samples. Normalized names do not include Go's trailing CPU suffix (for example, "-8").

func Parse

func Parse(r io.Reader) (Results, error)

Parse reads standard Go benchmark output. Non-benchmark lines and verbose benchmark headings are ignored; malformed benchmark result lines are rejected.

type Samples

type Samples struct {
	NanosecondsPerOperation []float64
	BytesPerOperation       []float64
	AllocationsPerOperation []float64
}

Samples contains all parsed observations for a benchmark. Repeated result lines and results with different CPU suffixes are combined.

Jump to

Keyboard shortcuts

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