benchmark

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2017 License: Apache-2.0 Imports: 8 Imported by: 30

Documentation

Overview

Package benchmark provides benchmarking facilities to the standard application system.

Index

Constants

This section is empty.

Variables

View Source
var (
	// GlobalCounters is a singleton set of performance counters.
	GlobalCounters = NewCounters()
)
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 Counter

type Counter interface {
	// Get retrieves the current value of the counter.
	Get() interface{}

	// Reset resets the counter to its initial value.
	Reset()

	// TypeName retrieves a string that uniquely identifies the
	// type of counter.
	TypeName() string
}

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) AllCounters

func (m *Counters) AllCounters() map[string]Counter

AllCounters retrieves a copy of the counter map, 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.

func (*Counters) Lazy

func (m *Counters) Lazy(name string) *LazyCounter

Lazy returns the LazyCounter with the given name, instantiating a new one if necessary.

func (*Counters) LazyWithCaching

func (m *Counters) LazyWithCaching(name string, f func() Counter) *LazyCounter

LazyWithCaching returns the LazyCounter with the given name, atomically instantiating a new one with the given caching function if necessary.

func (*Counters) LazyWithFunction

func (m *Counters) LazyWithFunction(name string, f func() Counter) *LazyCounter

LazyWithFunction returns the LazyCounter with the given name, atomically instantiating a new one with the given function if necessary.

func (*Counters) MarshalJSON

func (m *Counters) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*Counters) String

func (m *Counters) String(name string) *StringHolder

String returns the StringHolder with the given name, instantiating a new one if necessary.

func (*Counters) UnmarshalJSON

func (m *Counters) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type DurationCounter

type DurationCounter int64

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

func DurationCounterOf

func DurationCounterOf(t time.Duration) *DurationCounter

DurationCounterOf creates a new DurationCounter with the given duration.

func (*DurationCounter) AddDuration

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

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

func (*DurationCounter) Get

func (c *DurationCounter) Get() interface{}

Get implements Counter.

func (*DurationCounter) GetDuration

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

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

func (*DurationCounter) MarshalJSON

func (c *DurationCounter) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*DurationCounter) Reset

func (c *DurationCounter) Reset()

Reset implements Counter.

func (*DurationCounter) SetDuration

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

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) TypeName

func (c *DurationCounter) TypeName() string

TypeName implements Counter.

func (*DurationCounter) UnmarshalJSON

func (c *DurationCounter) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

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 IntegerCounterOf

func IntegerCounterOf(i int64) *IntegerCounter

IntegerCounterOf creates a new IntegerCounter with the given duration.

func (*IntegerCounter) AddInt64

func (c *IntegerCounter) AddInt64(i int64)

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

func (*IntegerCounter) Get

func (c *IntegerCounter) Get() interface{}

Get implements Counter.

func (*IntegerCounter) GetInt64

func (c *IntegerCounter) GetInt64() int64

GetInt64 retrieves the value of this counter as an int64.

func (*IntegerCounter) Increment

func (c *IntegerCounter) Increment()

AddInt64 adds 1 to the value of this counter.

func (*IntegerCounter) MarshalJSON

func (c *IntegerCounter) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaller.

func (*IntegerCounter) Reset

func (c *IntegerCounter) Reset()

Reset implements Counter.

func (*IntegerCounter) SetInt64

func (c *IntegerCounter) SetInt64(val int64)

func (*IntegerCounter) TypeName

func (c *IntegerCounter) TypeName() string

TypeName implements Counter.

func (*IntegerCounter) UnmarshalJSON

func (c *IntegerCounter) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type LazyCounter

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

LazyCounter is a Counter that delegates Counter method calls to a Counter retrieved by calling a function.

func (*LazyCounter) Counter

func (c *LazyCounter) Counter() Counter

Counter retrieves the Underlying counter.

func (*LazyCounter) Get

func (c *LazyCounter) Get() interface{}

Get implements Counter.

func (*LazyCounter) MarshalJSON

func (c *LazyCounter) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*LazyCounter) Reset

func (c *LazyCounter) Reset()

Reset implements Counter.

func (*LazyCounter) SetCaching

func (c *LazyCounter) SetCaching(f func() Counter)

SetCaching sets a function to be called to retrieve the underlying counter. This function will be called once, the first time one of the Counter methods is called.

func (*LazyCounter) SetFunction

func (c *LazyCounter) SetFunction(f func() Counter)

SetFunction sets the function to retrieve the underlying counter. This function will be called every time one of the Counter methods is called.

func (*LazyCounter) TypeName

func (c *LazyCounter) TypeName() string

TypeName implements 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.

type StringHolder

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

Holder is a Counter that holds a String.

func StringHolderOf

func StringHolderOf(s string) *StringHolder

StringHolderOf creates a new StringHolder with the given value.

func (*StringHolder) Get

func (c *StringHolder) Get() interface{}

Get implements Counter.

func (*StringHolder) GetString

func (c *StringHolder) GetString() string

GetString returns the string.

func (*StringHolder) MarshalJSON

func (c *StringHolder) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (*StringHolder) Reset

func (c *StringHolder) Reset()

Reset implements Counter.

func (*StringHolder) SetString

func (c *StringHolder) SetString(s string)

SetString sets the string in the holder.

func (*StringHolder) TypeName

func (c *StringHolder) TypeName() string

func (*StringHolder) UnmarshalJSON

func (c *StringHolder) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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