Documentation
¶
Overview ¶
Package stopwatch implements simple stopwatch functionality
Package stopwatch implements simple stopwatch functionality This package is only thread safe for the AddElapsed() call. Other usage assumes that usage is single threaded.
Index ¶
- Variables
- type NamedStopwatch
- func (ns *NamedStopwatch) Add(name string) error
- func (ns *NamedStopwatch) AddElapsedSince(name string, t time.Time)
- func (ns *NamedStopwatch) AddMany(names []string) error
- func (ns *NamedStopwatch) Delete(name string)
- func (ns *NamedStopwatch) Elapsed(name string) time.Duration
- func (ns *NamedStopwatch) ElapsedMilliSeconds(name string) float64
- func (ns *NamedStopwatch) ElapsedSeconds(name string) float64
- func (ns *NamedStopwatch) Exists(name string) bool
- func (ns *NamedStopwatch) Keys() []string
- func (ns *NamedStopwatch) Reset(name string)
- func (ns *NamedStopwatch) SetLogger(logger logger)
- func (ns *NamedStopwatch) Start(name string)
- func (ns *NamedStopwatch) StartMany(names []string)
- func (ns *NamedStopwatch) Stop(name string)
- func (ns *NamedStopwatch) StopMany(names []string)
- type Stopwatch
- func (s *Stopwatch) AddElapsedSince(t time.Time)
- func (s *Stopwatch) Elapsed() time.Duration
- func (s *Stopwatch) ElapsedMilliSeconds() float64
- func (s *Stopwatch) ElapsedSeconds() float64
- func (s *Stopwatch) IsRunning() bool
- func (s *Stopwatch) Reset()
- func (s *Stopwatch) SetStringFormat(f func(time.Duration) string)
- func (s *Stopwatch) Start()
- func (s *Stopwatch) Stop()
- func (s *Stopwatch) String() string
Constants ¶
This section is empty.
Variables ¶
var DefaultFormat = func(t time.Duration) string { return t.String() }
DefaultFormat allows the Stopwatch.String() function to be configured differently to time.Duration if needed. This is done at the global package level to avoid having to do on each Stopwatch instance.
Functions ¶
This section is empty.
Types ¶
type NamedStopwatch ¶
NamedStopwatch holds a map of string named stopwatches. Intended to be used when several Stopwatches are being used at once, and easy to use as they are name based.
func NewNamedStopwatch ¶
func NewNamedStopwatch() *NamedStopwatch
NewNamedStopwatch creates an empty Stopwatch list
func (*NamedStopwatch) Add ¶
func (ns *NamedStopwatch) Add(name string) error
Add adds a single Stopwatch name with the given name.
func (*NamedStopwatch) AddElapsedSince ¶
func (ns *NamedStopwatch) AddElapsedSince(name string, t time.Time)
AddElapsedSince adds the duration since the reference time to the given named stopwatch.
func (*NamedStopwatch) AddMany ¶
func (ns *NamedStopwatch) AddMany(names []string) error
AddMany adds several named stopwatches in one go
func (*NamedStopwatch) Delete ¶
func (ns *NamedStopwatch) Delete(name string)
Delete removes a Stopwatch with the given name (if it exists)
func (*NamedStopwatch) Elapsed ¶
func (ns *NamedStopwatch) Elapsed(name string) time.Duration
Elapsed returns the elapsed time.Duration of the named stopwatch if it exists or 0
func (*NamedStopwatch) ElapsedMilliSeconds ¶
func (ns *NamedStopwatch) ElapsedMilliSeconds(name string) float64
ElapsedMilliSeconds returns the elapsed time in milliseconds of the named stopwatch if it exists or 0.
func (*NamedStopwatch) ElapsedSeconds ¶
func (ns *NamedStopwatch) ElapsedSeconds(name string) float64
ElapsedSeconds returns the elapsed time in seconds of the named stopwatch if it exists or 0.
func (*NamedStopwatch) Exists ¶
func (ns *NamedStopwatch) Exists(name string) bool
Exists returns true if the NamedStopwatch exists
func (*NamedStopwatch) Keys ¶
func (ns *NamedStopwatch) Keys() []string
Keys returns the known names of Stopwatches
func (*NamedStopwatch) Reset ¶
func (ns *NamedStopwatch) Reset(name string)
Reset resets a NamedStopwatch if it exists
func (*NamedStopwatch) SetLogger ¶ added in v0.1.1
func (ns *NamedStopwatch) SetLogger(logger logger)
SetLogger is used to set the logger interface
func (*NamedStopwatch) Start ¶
func (ns *NamedStopwatch) Start(name string)
Start starts a NamedStopwatch if it exists
func (*NamedStopwatch) StartMany ¶
func (ns *NamedStopwatch) StartMany(names []string)
StartMany allows you to start several stopwatches in one go
func (*NamedStopwatch) Stop ¶
func (ns *NamedStopwatch) Stop(name string)
Stop stops a NamedStopwatch if it exists
func (*NamedStopwatch) StopMany ¶
func (ns *NamedStopwatch) StopMany(names []string)
StopMany allows you to stop several stopwatches in one go
type Stopwatch ¶
Stopwatch is a structure to hold information about a stopwatch
func Start ¶
Start returns a pointer to a new Stopwatch struct and indicates that the stopwatch has started.
func (*Stopwatch) AddElapsedSince ¶
AddElapsed just adds an elapsed time to the value that's been stored.
func (*Stopwatch) ElapsedMilliSeconds ¶
ElapsedMilliSeconds is a helper function returns the number of milliseconds since starting.
func (*Stopwatch) ElapsedSeconds ¶
ElapsedSeconds is a helper function returns the number of seconds since starting.
func (*Stopwatch) IsRunning ¶
IsRunning is a helper function to indicate if in theory the stopwatch is working.
func (*Stopwatch) SetStringFormat ¶
SetStringFormat allows the String() function to be configured differently to time.Duration for the specific Stopwatch.
func (*Stopwatch) Start ¶
func (s *Stopwatch) Start()
Start records that we are now running. If called previously this is a no-op and the existing refTime is not touched.