internal

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RED    = "\033[31m"
	GREEN  = "\033[32m"
	YELLOW = "\033[33m"
	BLUE   = "\033[34m"
	PURPLE = "\033[35m"
	CYAN   = "\033[36m"
	RESET  = "\033[0m"
)

colors

Variables

View Source
var ErrInvalidTimeUnit = errors.New("invalid time unit")
View Source
var NO_COLOR bool = false

NO_COLOR is a global variable that can be set to disable color output.

View Source
var OUTLIER_THRESHOLD = 0.0

can be modified by the outlier-threshold flag

Functions

func CalculateAverage

func CalculateAverage(data []float64) float64

func CalculateStandardDeviation

func CalculateStandardDeviation(data []float64, avg float64) float64

Computes the standard deviation of the given data.

func CheckForUpdates

func CheckForUpdates(currentVersion string, updateCh *chan string)

func DurationFromNumber

func DurationFromNumber[T numberLike](number T, unit time.Duration) time.Duration

func Export

func Export(formats []string, filename string, results []*SpeedResult, timeUnit time.Duration)

func FilterFunc

func FilterFunc[T any, Ts ~[]T](function func(T) bool, slice Ts) Ts

FilterFunc takes a predicate function and returns all the elements of the slice which return true for the function.

func Log

func Log(color, message string)

todo refactor this to use colorstring module Log prints the given message in the given color.

func MapFunc

func MapFunc[Ts ~[]T, Ss ~[]S, T, S any](function func(T) S, slice Ts) Ss

MapFunc returns a slice of all elements in the given slice mapped by the given function.

func ModifyTimeUnit

func ModifyTimeUnit(results []*SpeedResult, timeUnit time.Duration)

ModifyTimeUnit takes a slice of SpeedResult and modifies its every attribute to suit accordingly to the given timeUnit.

func ParseTimeUnit

func ParseTimeUnit(unitString string) (time.Duration, error)

func Plot

func Plot(plotFormats []string, results []*SpeedResult, timeUnit time.Duration)

func RelativeSummary

func RelativeSummary(results []*SpeedResult)

Prints the relative summary and also sets the RelativeMean and RelativeStddev of each SpeedResult.

func TestOutliers

func TestOutliers(data []float64) bool

Returns true if there are any statistical outliers in the data.

func VerifyExportFormats

func VerifyExportFormats(formats string) ([]string, error)

func VerifyPlotFormats

func VerifyPlotFormats(formats string) ([]string, error)

Types

type ByAverage

type ByAverage []*SpeedResult

Implements sort.Interface for []Result based on the Average field.

func (ByAverage) Len

func (a ByAverage) Len() int

func (ByAverage) Less

func (a ByAverage) Less(i, j int) bool

func (ByAverage) Swap

func (a ByAverage) Swap(i, j int)

type PrintableResult

type PrintableResult struct {
	Command           string
	Runs              int
	AverageElapsed    string
	AverageUser       string
	AverageSystem     string
	StandardDeviation string
	Min               string
	Max               string
}

PrintableResult struct which is shown at the end as benchmarking summary and is written to a file. Other numerical quantities except runs are represented as strings because they are durations, and time.Duration offers a .String() method.

func NewPrintableResult

func NewPrintableResult() *PrintableResult

func (*PrintableResult) FromSpeedResult

func (pr *PrintableResult) FromSpeedResult(sr SpeedResult) *PrintableResult

func (*PrintableResult) String

func (result *PrintableResult) String() string

Consolify prints the benchmark summary of the Result struct to the console, with color codes.

type SpeedResult

type SpeedResult struct {
	Command           string    `json:"command,omitempty"`
	AverageElapsed    float64   `json:"mean,omitempty"`
	AverageUser       float64   `json:"user,omitempty"`
	AverageSystem     float64   `json:"system,omitempty"`
	StandardDeviation float64   `json:"stddev,omitempty"`
	Max               float64   `json:"max,omitempty"`
	Min               float64   `json:"min,omitempty"`
	Times             []float64 `json:"times,omitempty"`
	RelativeMean      float64   `json:"relative_mean,omitempty"`
	RelativeStddev    float64   `json:"relative_stddev,omitempty"`
}

Contains all the numerical quantities (in microseconds) for relative speed comparison. Also used for export.

Jump to

Keyboard shortcuts

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