Documentation ¶
Overview ¶
Package benchmark provides benchmarking facilities to the standard application system.
Index ¶
- Variables
- type Complexity
- type Counter
- type Counters
- func (m *Counters) AllCounters() map[string]Counter
- func (m *Counters) Duration(name string) *DurationCounter
- func (m *Counters) Integer(name string) *IntegerCounter
- func (m *Counters) Lazy(name string) *LazyCounter
- func (m *Counters) LazyWithCaching(name string, f func() Counter) *LazyCounter
- func (m *Counters) LazyWithFunction(name string, f func() Counter) *LazyCounter
- func (m *Counters) MarshalJSON() ([]byte, error)
- func (m *Counters) String(name string) *StringHolder
- func (m *Counters) UnmarshalJSON(data []byte) error
- type DurationCounter
- func (c *DurationCounter) AddDuration(t time.Duration)
- func (c *DurationCounter) Get() interface{}
- func (c *DurationCounter) GetDuration() time.Duration
- func (c *DurationCounter) MarshalJSON() ([]byte, error)
- func (c *DurationCounter) Reset()
- func (c *DurationCounter) SetDuration(t time.Duration)
- func (c *DurationCounter) Start() time.Time
- func (c *DurationCounter) Stop(startTime time.Time)
- func (c *DurationCounter) TypeName() string
- func (c *DurationCounter) UnmarshalJSON(data []byte) error
- type Fit
- type IntegerCounter
- func (c *IntegerCounter) AddInt64(i int64)
- func (c *IntegerCounter) Get() interface{}
- func (c *IntegerCounter) GetInt64() int64
- func (c *IntegerCounter) Increment()
- func (c *IntegerCounter) MarshalJSON() ([]byte, error)
- func (c *IntegerCounter) Reset()
- func (c *IntegerCounter) SetInt64(val int64)
- func (c *IntegerCounter) TypeName() string
- func (c *IntegerCounter) UnmarshalJSON(data []byte) error
- type LazyCounter
- func (c *LazyCounter) Counter() Counter
- func (c *LazyCounter) Get() interface{}
- func (c *LazyCounter) MarshalJSON() ([]byte, error)
- func (c *LazyCounter) Reset()
- func (c *LazyCounter) SetCaching(f func() Counter)
- func (c *LazyCounter) SetFunction(f func() Counter)
- func (c *LazyCounter) TypeName() string
- type LinearFit
- type Sample
- type Samples
- type StringHolder
- func (c *StringHolder) Get() interface{}
- func (c *StringHolder) GetString() string
- func (c *StringHolder) MarshalJSON() ([]byte, error)
- func (c *StringHolder) Reset()
- func (c *StringHolder) SetString(s string)
- func (c *StringHolder) TypeName() string
- func (c *StringHolder) UnmarshalJSON(data []byte) error
Constants ¶
This section is empty.
Variables ¶
var ( // GlobalCounters is a singleton set of performance counters. GlobalCounters = NewCounters() )
var LinearTime linearTime
LinearTime represents an algorithmic complexity of O(n).
Functions ¶
This section is empty.
Types ¶
type Complexity ¶
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 (*Counters) AllCounters ¶
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 ¶
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 ¶
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) 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) 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 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) 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) 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) MarshalJSON ¶
func (c *LazyCounter) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
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.
type LinearFit ¶
type LinearFit struct {
// contains filtered or unexported fields
}
LinearFit is a linear time fitting (y = α + βx).
func NewLinearFit ¶
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) AddOrUpdate ¶
Add appends the sample to the list. If there already is a sample with that index, overwrite the duration for it.
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) 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) 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