Benchee v0.5.0 Benchee.Conversion.Scale behaviour

Functions for scaling values to other units. Different domains handle this task differently, for example durations and counts.

See Benchee.Conversion.Count and Benchee.Conversion.Duration for examples

Summary

Functions

Given a list of number values and a module describing the domain of the values (e.g. Duration, Count), finds the “best fit” unit for the list as a whole

Used internally for scaling but only supports scaling with actual units

Used internally by implemented units to handle their scaling with units and without

Lookup a unit by its atom presentation for the representation of supported units. Used by Benchee.Conversion.Duration and Benchee.Conversion.Count

Callbacks

Returns the base_unit in which Benchee takes its measurements, which in general is the smallest supported unit

Finds the best fit unit for a list of numbers in a domain’s base unit. “Best fit” is the most common unit, or (in case of tie) the largest of the most common units

Scales a number in a domain’s base unit to an equivalent value in the best fit unit. Results are a {number, unit} tuple. See Benchee.Conversion.Count and Benchee.Conversion.Duration for examples

Scales a number in a domain’s base unit to an equivalent value in the specified unit. Results are a {number, unit} tuple. See Benchee.Conversion.Count and Benchee.Conversion.Duration for examples

Given the atom representation of a unit (:hour) return the appropriate Benchee.Conversion.Unit struct

Types

any_unit()
options()
options :: [{atom, atom}]
scaled_number()
scaled_number :: {number, unit}
unit_atom()
unit_atom :: atom

Functions

best_unit(list, module, opts)

Given a list of number values and a module describing the domain of the values (e.g. Duration, Count), finds the “best fit” unit for the list as a whole.

The best fit unit for a given value is the smallest unit in the domain for which the scaled value is at least 1. For example, the best fit unit for a count of 1_000_000 would be :million.

The best fit unit for the list as a whole depends on the :strategy passed in opts:

  • :best - the most frequent best fit unit. In case of tie, the largest of the most frequent units
  • :largest - the largest best fit unit
  • :smallest - the smallest best fit unit
  • :none - the domain’s base (unscaled) unit

Examples

iex> list = [1, 101, 1_001, 10_001, 100_001, 1_000_001]
iex> Benchee.Conversion.Scale.best_unit(list, Benchee.Conversion.Count, strategy: :best).name
:thousand

iex> list = [1, 101, 1_001, 10_001, 100_001, 1_000_001]
iex> Benchee.Conversion.Scale.best_unit(list, Benchee.Conversion.Count, strategy: :smallest).name
:one

iex> list = [1, 101, 1_001, 10_001, 100_001, 1_000_001]
iex> Benchee.Conversion.Scale.best_unit(list, Benchee.Conversion.Count, strategy: :largest).name
:million
scale(value, unit)

Used internally for scaling but only supports scaling with actual units.

Examples

iex> unit = %Benchee.Conversion.Unit{magnitude: 1000}
iex> Benchee.Conversion.Scale.scale 12345, unit
12.345
scale(value, unit_atom, module)

Used internally by implemented units to handle their scaling with units and without.

Examples

iex> Benchee.Conversion.Scale.scale(12345, :thousand, Benchee.Conversion.Count)
12.345
unit_for(units, unit)

Lookup a unit by its atom presentation for the representation of supported units. Used by Benchee.Conversion.Duration and Benchee.Conversion.Count.

Callbacks

base_unit()
base_unit :: unit

Returns the base_unit in which Benchee takes its measurements, which in general is the smallest supported unit.

best(list, options)
best(list, options) :: unit

Finds the best fit unit for a list of numbers in a domain’s base unit. “Best fit” is the most common unit, or (in case of tie) the largest of the most common units.

scale(number)
scale(number) :: scaled_number

Scales a number in a domain’s base unit to an equivalent value in the best fit unit. Results are a {number, unit} tuple. See Benchee.Conversion.Count and Benchee.Conversion.Duration for examples

scale(number, any_unit)
scale(number, any_unit) :: number

Scales a number in a domain’s base unit to an equivalent value in the specified unit. Results are a {number, unit} tuple. See Benchee.Conversion.Count and Benchee.Conversion.Duration for examples

unit_for(unit_atom)
unit_for(unit_atom) :: unit

Given the atom representation of a unit (:hour) return the appropriate Benchee.Conversion.Unit struct.