Documentation ¶
Overview ¶
Package benchunit manipulates benchmark units and formats numbers in those units.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var NoOpScaler = Scaler{-1, 1, ""}
NoOpScaler is a Scaler that formats numbers with the smallest number of digits necessary to capture the exact value, and no prefix. This is intended for when the output will be consumed by another program, such as when producing CSV format.
Functions ¶
func Scale ¶
Scale formats val using at least three significant digits, appending an SI or binary prefix. See Scaler.Format for details.
Types ¶
type Class ¶
type Class int
A Class specifies what class of unit prefixes are in use.
const ( // Decimal indicates values of a given unit should be scaled // by powers of 1000. Decimal units use the International // System of Units SI prefixes, such as "k", and "M". Decimal Class = iota // Binary indicates values of a given unit should be scaled by // powers of 1024. Binary units use the International // Electrotechnical Commission (IEC) binary prefixes, such as // "Ki" and "Mi". Binary )
type Scaler ¶
type Scaler struct { Prec int // Digits after the decimal point Factor float64 // Unscaled value of 1 Prefix (e.g., 1 k => 1000) Prefix string // Unit prefix ("k", "M", "Ki", etc) }
A Scaler represents a scaling factor for a number and its scientific representation.
func CommonScale ¶
CommonScale returns a common Scaler to apply to all values in vals. This scale will show at least three significant digits for every value.
func (Scaler) Format ¶
Format formats val and appends the unit prefix according to the given scale. For example, if the Scaler has class Decimal, Format(123456789) returns "123.4M".
If the value has units, be sure to tidy it first (see Tidy). Otherwise, this can result in nonsense units when the result is displayed with its units; for example, representing 123456789 ns as 123.4M ns ("megananoseconds", aka milliseconds).