benchmark

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 28, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package benchmark provides the representation of a single benchmark consisting of a function and its converted types.

Package benchmark helper methods

Index

Constants

View Source
const (
	// Milli Milliseconds
	Milli ConversionType = "ms"
	// Micro Microseconds
	Micro = "us"
	// Nano Nanoseconds
	Nano = "ns"
	// Sec Seconds
	Sec = "s"
	// Min Minutes
	Min = "m"
	// Hr Hours
	Hr = "hr"
)

Variables

This section is empty.

Functions

func GetFunctionName

func GetFunctionName(i interface{}) string

GetFunctionName get the running function name of a objectBenchmark. ref: https://stackoverflow.com/a/7053871

Types

type Benchmark

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

Benchmark Represents a single instance of a benchmark.

func NewBenchmark

func NewBenchmark(description string, function func(), iterations int, units ...ConversionType) Benchmark

NewBenchmark create a new Benchmark Object.

func (*Benchmark) GetConvertedType

func (benchmark *Benchmark) GetConvertedType(t ConversionType) time.Duration

GetConvertedType get ConvertedType according to t (ConversionType).

func (Benchmark) GetDesc

func (benchmark Benchmark) GetDesc() string

GetDesc get the description of the benchmark.

func (Benchmark) GetElapsedTime

func (benchmark Benchmark) GetElapsedTime() time.Duration

GetElapsedTime get the the elapsed time.

func (Benchmark) GetFunction

func (benchmark Benchmark) GetFunction() func()

GetFunction get the measuring function.

func (Benchmark) GetIterations

func (benchmark Benchmark) GetIterations() int

GetIterations get the number of iterations.

func (*Benchmark) GetStates

func (benchmark *Benchmark) GetStates() map[string]time.Duration

GetStates get time.Duration at each time in a key value pair of iterations and durations.

func (Benchmark) GetUnits

func (benchmark Benchmark) GetUnits() []ConversionType

GetUnits get the units that the user wants during execution.

func (Benchmark) Main

func (benchmark Benchmark) Main()

Main start running the benchmark.

func (*Benchmark) Start

func (benchmark *Benchmark) Start()

Start starts the timer for measuring the function.

func (*Benchmark) TimeElapsed

func (benchmark *Benchmark) TimeElapsed(units []ConversionType)

TimeElapsed calculates time elapsed and performs conversion of units.

type ConversionType

type ConversionType string

ConversionType represents a unit that can be converted.

Jump to

Keyboard shortcuts

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