benchmark

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColorReset  = "\033[0m"
	ColorRed    = "\033[31m"
	ColorGreen  = "\033[32m"
	ColorYellow = "\033[33m"
	ColorBlue   = "\033[34m"
)

ANSI Color Codes for output.

Variables

This section is empty.

Functions

func Bits

func Bits(defaults ...uint64) ([]uint64, error)

Bits parses the package-level `-bits` flag and returns a slice of bit sizes. If the flag is empty the provided defaults are returned. The returned values are uint64 and an error is returned if parsing fails.

func Curves

func Curves(curveIDs ...math.CurveID) []math.CurveID

Curves parses the package-level `-curves` flag and returns a slice of math.CurveID. The flag may contain comma-separated numeric curve IDs or known curve names (e.g. "BN254", "BLS12_381_BBS_GURVY", "BLS12_381_BBS_GURVY_FAST_RNG"). If the flag is empty, the provided curveIDs are returned as defaults.

func Duration

func Duration() time.Duration

Duration returns the parsed package-level `-duration` flag as a time.Duration. If the flag is zero, Duration returns 1 second as a sane default.

func Integers

func Integers[T constraints.Integer](str string, defaults ...T) ([]T, error)

Integers is a generic helper that parses a comma-separated string of unsigned integers into a slice of type T (which must be an integer type). If the input string is empty the provided defaults are returned. It trims whitespace and returns a parsing error on invalid numeric values.

func NumInputs

func NumInputs(defaults ...int) ([]int, error)

NumInputs parses the package-level `-num_inputs` flag and returns a slice of ints. If the flag is empty the provided defaults are returned. Parsing errors are returned.

func NumOutputs

func NumOutputs(defaults ...int) ([]int, error)

NumOutputs parses the package-level `-num_outputs` flag and returns a slice of ints. If the flag is empty the provided defaults are returned. Parsing errors are returned.

func Workers

func Workers(defaults ...int) ([]int, error)

Workers parses the package-level `-workers` flag and returns a slice of worker counts. The flag accepts comma-separated integers and the special token "NumCPU" which is translated to the runtime.NumCPU() value. If the flag is empty the provided defaults are returned. Parsing errors are returned.

Types

type Bucket

type Bucket struct {
	LowBound  time.Duration
	HighBound time.Duration
	Count     int
}

Bucket represents a latency range and its frequency.

type Case

type Case struct {
	Workers    int
	Bits       uint64
	CurveID    math.CurveID
	NumInputs  int
	NumOutputs int
}

type Result

type Result struct {
	GoRoutines    int
	OpsTotal      uint64
	Duration      time.Duration
	OpsPerSecReal float64
	OpsPerSecPure float64

	AvgLatency    time.Duration
	StdDevLatency time.Duration
	Variance      float64

	P50Latency time.Duration
	P75Latency time.Duration
	P95Latency time.Duration
	P99Latency time.Duration
	MinLatency time.Duration
	MaxLatency time.Duration

	IQR    time.Duration // Interquartile Range (measure of spread)
	Jitter time.Duration // Avg change between consecutive latencies

	CoeffVar    float64
	BytesPerOp  uint64
	AllocsPerOp uint64

	Histogram []Bucket
}

Result holds the comprehensive benchmark metrics.

func RunBenchmark

func RunBenchmark[T any](
	workers int,
	benchDuration time.Duration,
	setup func() T,
	work func(T),
) Result

func (Result) Print

func (r Result) Print()

type TestCase

type TestCase struct {
	Name          string
	BenchmarkCase *Case
}

func GenerateCases

func GenerateCases(bits []uint64, curves []math.CurveID, inputs []int, outputs []int, workers []int) []TestCase

GenerateCases returns all combinations of Case created from the provided slices of bits, curve IDs, number of inputs and outputs.

Jump to

Keyboard shortcuts

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