units

package
v0.0.0-...-c9cfaf6 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package units implements human-friendly representations of common units.

Index

Constants

View Source
const (
	Runtime        = "ns/op"
	DataRate       = "MB/s"
	BytesAllocated = "B/op"
	Allocs         = "allocs/op"
)

Standard library testing package units.

Variables

This section is empty.

Functions

func Less

func Less(a, b string) bool

Less is a comparison function for units.

Types

type ImprovementDirection

type ImprovementDirection int

ImprovementDirection indicates which direction of change is considered better.

const (
	ImprovementDirectionUnknown ImprovementDirection = 0
	ImprovementDirectionLarger  ImprovementDirection = 1
	ImprovementDirectionSmaller ImprovementDirection = -1
)

Supported improvement direction values.

func ImprovementDirectionForUnit

func ImprovementDirectionForUnit(unit string) ImprovementDirection

ImprovementDirectionForUnit returns the improvement direction for the supplied unit, if known.

func ImprovementDirectionString

func ImprovementDirectionString(s string) (ImprovementDirection, error)

ImprovementDirectionString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func ImprovementDirectionValues

func ImprovementDirectionValues() []ImprovementDirection

ImprovementDirectionValues returns all values of the enum

func (ImprovementDirection) IsAImprovementDirection

func (i ImprovementDirection) IsAImprovementDirection() bool

IsAImprovementDirection returns "true" if the value is listed in the enum definition. "false" otherwise

func (ImprovementDirection) String

func (i ImprovementDirection) String() string

type Quantity

type Quantity struct {
	Value float64
	Unit  string
}

Quantity is a value in some unit.

func BytesBinary

func BytesBinary(b float64) Quantity

BytesBinary represents the given number of bytes with binary prefixes (multiples of 1024).

func BytesSI

func BytesSI(b float64) Quantity

BytesSI represents the given number of bytes with SI units (multiples of 1000).

func Duration

func Duration(ns float64) Quantity

Duration represents a nanosecond quantity in time units up to hours.

func Frequency

func Frequency(f float64) Quantity

Frequency represents a frequency in Hertz.

func Humanize

func Humanize(q Quantity) Quantity

Humanize attempts to represent q in a more friendly unit for human consumption.

func (Quantity) Format

func (q Quantity) Format() string

Format quantity with precision suitable for the unit.

func (Quantity) FormatValue

func (q Quantity) FormatValue() string

FormatValue formats the value with precision suitable for the unit.

func (Quantity) FormatValueWithPrecision

func (q Quantity) FormatValueWithPrecision(prec int) string

FormatValueWithPrecision formats the value with up to prec significant digits.

func (Quantity) FormatWithPrecision

func (q Quantity) FormatWithPrecision(prec int) string

FormatWithPrecision formats the quantity with up to prec significant digits.

func (Quantity) String

func (q Quantity) String() string

Jump to

Keyboard shortcuts

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