benchmark

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToMB

func BytesToMB(bytes uint64) float64

BytesToMB converts bytes to megabytes

func CompareWithBaseline

func CompareWithBaseline(current []BenchmarkResult, baseline *Baseline, threshold float64) ([]string, error)

CompareWithBaseline compares current results with baseline

func GetTestContext

func GetTestContext() (context.Context, context.CancelFunc)

GetTestContext returns a context with reasonable timeout for benchmarks

func MeasureMemory

func MeasureMemory() runtime.MemStats

MeasureMemory captures current memory statistics

func MinDuration

func MinDuration(d time.Duration, min time.Duration) time.Duration

MinDuration ensures a minimum duration for timing measurements

func NewConfig

func NewConfig() interface{}

NewConfig creates a config object for benchmarking This wraps the actual config package implementation

func NewRootCmd

func NewRootCmd() interface{}

NewRootCmd creates a root command for benchmarking This wraps the actual cmd package implementation

func NsToMs

func NsToMs(ns int64) float64

NsToMs converts nanoseconds to milliseconds

func SaveBaseline

func SaveBaseline(results []BenchmarkResult, path string) error

SaveBaseline saves benchmark results as baseline

func SaveReport

func SaveReport(report *BenchmarkReport, path string) error

SaveReport saves the benchmark report to a file

Types

type Baseline

type Baseline struct {
	Timestamp time.Time                  `json:"timestamp"`
	Results   map[string]BenchmarkResult `json:"results"`
}

Baseline represents baseline measurements for regression detection

func LoadBaseline

func LoadBaseline(path string) (*Baseline, error)

LoadBaseline loads baseline measurements from file

type BenchmarkReport

type BenchmarkReport struct {
	Timestamp time.Time         `json:"timestamp"`
	Results   []BenchmarkResult `json:"results"`
	Summary   BenchmarkSummary  `json:"summary"`
}

BenchmarkReport contains all benchmark results

func GenerateReport

func GenerateReport(results []BenchmarkResult, baseline *Baseline) *BenchmarkReport

GenerateReport creates a comprehensive benchmark report

type BenchmarkResult

type BenchmarkResult struct {
	Name         string    `json:"name"`
	Iterations   int       `json:"iterations"`
	NsPerOp      int64     `json:"ns_per_op"`
	MsPerOp      float64   `json:"ms_per_op"`
	BytesPerOp   int64     `json:"bytes_per_op"`
	AllocsPerOp  int64     `json:"allocs_per_op"`
	MemAllocMB   float64   `json:"mem_alloc_mb"`
	Timestamp    time.Time `json:"timestamp"`
	GoVersion    string    `json:"go_version"`
	OS           string    `json:"os"`
	Arch         string    `json:"arch"`
	PassedTarget bool      `json:"passed_target"`
	TargetValue  float64   `json:"target_value,omitempty"`
	ActualValue  float64   `json:"actual_value,omitempty"`
	TargetUnit   string    `json:"target_unit,omitempty"`
}

BenchmarkResult represents a single benchmark result

func RecordResult

func RecordResult(b *testing.B, name string, targetMs float64) BenchmarkResult

RecordResult records a benchmark result with target validation

type BenchmarkSummary

type BenchmarkSummary struct {
	TotalBenchmarks int     `json:"total_benchmarks"`
	PassedTargets   int     `json:"passed_targets"`
	FailedTargets   int     `json:"failed_targets"`
	AverageNsPerOp  float64 `json:"average_ns_per_op"`
	TotalAllocsMB   float64 `json:"total_allocs_mb"`
}

BenchmarkSummary provides high-level statistics

type TB

type TB interface {
	Fatalf(format string, args ...interface{})
	Helper()
}

TB is an interface that both *testing.T and *testing.B implement

type TestHelper

type TestHelper struct {
	TempDir string
	Cleanup func()
}

TestHelper provides common test utilities

func NewTestHelper

func NewTestHelper(tb TB) *TestHelper

NewTestHelper creates a new test helper with cleanup

Jump to

Keyboard shortcuts

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