Help us shape the future of Go! Take the 2026 Go Developer Survey

budgetfile

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package budgetfile compares measured sizes against a committed baseline.

Baselines live in testdata/budgets/<file>.json (one file per package, so parallel changes do not collide). A plain `go test` only reads them; they are rewritten solely when HM_BUDGETS_UPDATE=1 (see `make budgets-update`). The package is a leaf: standard library only.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(t testing.TB, file, key string, got int64, def Metric)

Check fails t when got exceeds baseline+tolerance or the cap, or when key is missing from the file. It always logs

BUDGET <file>/<key> got=N baseline=N limit=N unit=U status=ok|FAIL|under

With HM_BUDGETS_UPDATE=1 it instead rewrites the metric's value (keeping Tol*/Cap; a new key is added with def), requires HM_BUDGETS_REASON, appends a history line and never fails on size.

func CheckAllocs

func CheckAllocs(t *testing.T, file, name string, bench func(*testing.B))

CheckAllocs runs bench three times (testing.Benchmark) and checks the minimum allocs/op and bytes/op as <name>_allocs and <name>_bytes. Allocation counts are deterministic where wall clock is not. It skips under -short and -race (the race detector changes allocation behaviour).

Types

type Entry

type Entry struct {
	Reason string `json:"reason"`
	Date   string `json:"date"`
}

Entry is one line of a file's update history.

type Metric

type Metric struct {
	Value  int64   `json:"value"`
	Unit   string  `json:"unit"` // bytes | allocs
	TolPct float64 `json:"tol_pct,omitempty"`
	TolAbs int64   `json:"tol_abs,omitempty"`
	Cap    int64   `json:"cap,omitempty"` // absolute hard limit, 0 = none
}

Metric is one baseline entry.

Jump to

Keyboard shortcuts

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