benchmark

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package benchmark provides benchmarking facilities to the standard application system.

Index

Constants

This section is empty.

Variables

View Source
var GlobalCounters = NewCounters()

GlobalCounters is a singleton set of performance counters.

View Source
var LinearTime linearTime

LinearTime represents an algorithmic complexity of O(n).

Functions

This section is empty.

Types

type Complexity

type Complexity interface {
	Fit(samples Samples) (fit Fit, err float64)
}

Complexity represents the complexity of an algorithm.

type Counters

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

Counters represents a collection of named performance counters.

Individual counters are created on retrieve if they do not exist. Counters of different types with the same name are disallowed. Users are encouraged to hang on to retrieved counters rather than calling these methods repeatedly, for performance reasons.

func NewCounters

func NewCounters() *Counters

NewCounters allocates a new set of counters.

func (*Counters) All

func (m *Counters) All() map[string]interface{}

All retrieves a copy of the counters keyed by name.

func (*Counters) Duration

func (m *Counters) Duration(name string) *DurationCounter

Duration returns the DurationCounter with the given name, instantiating a new one if necessary.

func (*Counters) Integer

func (m *Counters) Integer(name string) *IntegerCounter

Integer returns the IntegerCounter with the given name, instantiating a new one if necessary.

type DurationCounter

type DurationCounter int64

DurationCounter is a Counter that holds an int64, exposed as a time.Duration.

func Duration

func Duration(name string) *DurationCounter

Duration is a convenience function for calling GlobalCounters.Duration(name).

func (*DurationCounter) Add

func (c *DurationCounter) Add(t time.Duration)

Add adds the given duration to the value of this counter.

func (*DurationCounter) Get

func (c *DurationCounter) Get() time.Duration

Get retrieves the value of this counter as a time.Duration.

func (*DurationCounter) Reset

func (c *DurationCounter) Reset()

Reset resets the duration to 0.

func (*DurationCounter) Set

func (c *DurationCounter) Set(t time.Duration)

Set resets the counter to t.

func (*DurationCounter) Start

func (c *DurationCounter) Start() time.Time

Start returns the current time. It's meant to be used with Stop() as a way to time blocks of code and add their durations to the counter.

func (*DurationCounter) Stop

func (c *DurationCounter) Stop(startTime time.Time)

Stop adds to the value of this counter the Duration elapsed since the time.Time received as argument.

func (*DurationCounter) Time

func (c *DurationCounter) Time(f func())

Time times the call to f, adding the timed duration to the counter.

type Fit

type Fit interface {
	String() string
}

Fit represents a complexity fit for the samples.

type IntegerCounter

type IntegerCounter int64

IntegerCounter is a Counter that holds an int64 value.

func Integer

func Integer(name string) *IntegerCounter

Integer is a convenience function for calling GlobalCounters.Integer(name).

func (*IntegerCounter) Add

func (c *IntegerCounter) Add(i int64)

Add adds the given value to the value of this counter.

func (*IntegerCounter) Get

func (c *IntegerCounter) Get() int64

Get implements counter.

func (*IntegerCounter) Increment

func (c *IntegerCounter) Increment()

Increment adds 1 to the value of this counter.

func (*IntegerCounter) Reset

func (c *IntegerCounter) Reset()

Reset resets the counter to 0.

func (*IntegerCounter) Set

func (c *IntegerCounter) Set(v int64)

Set assigns v to the counter.

type LinearFit

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

LinearFit is a linear time fitting (y = α + βx).

func NewLinearFit

func NewLinearFit(α, β time.Duration) LinearFit

func (LinearFit) String

func (f LinearFit) String() string

type Sample

type Sample struct {
	Index int           // Index of the sample
	Time  time.Duration // Duration of the sample.
}

Sample represents a single benchmark sample.

type Samples

type Samples []Sample

Samples is a list of samples

func (*Samples) Add

func (s *Samples) Add(index int, duration time.Duration)

Add appends the sample to the list.

func (*Samples) AddOrUpdate

func (s *Samples) AddOrUpdate(index int, duration time.Duration)

Add appends the sample to the list. If there already is a sample with that index, overwrite the duration for it.

func (Samples) Analyse

func (s Samples) Analyse() Fit

Analyse analyses the samples and returns the algorithmic cost.

func (Samples) Len

func (s Samples) Len() int

Len is the number of elements in the collection.

func (Samples) Less

func (s Samples) Less(i, j int) bool

Less reports whether the element with index i should sort before the element with index j.

func (Samples) String

func (s Samples) String() string

func (Samples) Swap

func (s Samples) Swap(i, j int)

Swap swaps the elements with indexes i and j.

Jump to

Keyboard shortcuts

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