bench

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package bench provides utilities for collecting and analyzing performance measurements.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bench

type Bench struct {
	// contains filtered or unexported fields
}

Bench tracks timing samples over a configurable duration for benchmarking.

func (*Bench) End

func (b *Bench) End()

End records the total elapsed time since Start was called.

func (*Bench) IsTestFinished

func (b *Bench) IsTestFinished() bool

IsTestFinished reports whether the benchmark has run long enough and collected enough samples.

func (*Bench) Measure

func (b *Bench) Measure(fn func() error) error

Measure times the execution of fn and records the duration as a sample.

func (*Bench) Results

func (b *Bench) Results() Results

Results returns a snapshot of the collected benchmark results.

func (*Bench) SetDuration

func (b *Bench) SetDuration(d time.Duration)

SetDuration sets the expected total duration for the benchmark run.

func (*Bench) Start

func (b *Bench) Start()

Start begins the benchmark timer.

type Results

type Results struct {
	Samples     []time.Duration
	TotDuration time.Duration
}

Results holds the collected timing samples and total duration of a benchmark run.

func (Results) Avg

func (r Results) Avg() time.Duration

Avg returns the arithmetic mean of all collected samples.

func (Results) Percentile

func (r Results) Percentile(pctile float64) time.Duration

Percentile returns the sample value at the given percentile (0.0 to 1.0).

Jump to

Keyboard shortcuts

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