Documentation
¶
Index ¶
- func BytesToMB(bytes uint64) float64
- func CompareWithBaseline(current []BenchmarkResult, baseline *Baseline, threshold float64) ([]string, error)
- func GetTestContext() (context.Context, context.CancelFunc)
- func MeasureMemory() runtime.MemStats
- func MinDuration(d time.Duration, min time.Duration) time.Duration
- func NewConfig() interface{}
- func NewRootCmd() interface{}
- func NsToMs(ns int64) float64
- func SaveBaseline(results []BenchmarkResult, path string) error
- func SaveReport(report *BenchmarkReport, path string) error
- type Baseline
- type BenchmarkReport
- type BenchmarkResult
- type BenchmarkSummary
- type TB
- type TestHelper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
MeasureMemory captures current memory statistics
func MinDuration ¶
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 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 ¶
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