Benchee v0.5.0 Benchee.Conversion.Count
Unit scaling for counts, such that 1000000 can be converted to 1 Million.
Summary
Functions
The raw count, unscaled
Finds the best unit for a list of counts. By default, chooses the most common unit. In case of tie, chooses the largest of the most common units
Formats a number as a string, with a unit label. To specify the unit, pass
a tuple of {value, unit_atom}
like {1_234, :million}
Scales a value representing a count in ones into a larger unit if appropriate
Scales a value representing a count in ones into a specified unit
Get a unit by its atom representation
Functions
Finds the best unit for a list of counts. By default, chooses the most common unit. In case of tie, chooses the largest of the most common units.
Pass [strategy: :smallest]
to always return the smallest unit in the list.
Pass [strategy: :largest]
to always return the largest unit in the list.
Examples
iex> Benchee.Conversion.Count.best([23, 23_000, 34_000, 2_340_000]).name
:thousand
iex> Benchee.Conversion.Count.best([23, 23_000, 34_000, 2_340_000, 3_450_000]).name
:million
iex> Benchee.Conversion.Count.best([23, 23_000, 34_000, 2_340_000], strategy: :smallest).name
:one
iex> Benchee.Conversion.Count.best([23, 23_000, 34_000, 2_340_000], strategy: :largest).name
:million
Formats a number as a string, with a unit label. To specify the unit, pass
a tuple of {value, unit_atom}
like {1_234, :million}
Examples
iex> Benchee.Conversion.Count.format(45_678.9)
"45.68 K"
iex> Benchee.Conversion.Count.format(45.6789)
"45.68"
iex> Benchee.Conversion.Count.format({45.6789, :thousand})
"45.68 K"
iex> Benchee.Conversion.Count.format({45.6789, %Benchee.Conversion.Unit{long: "Thousand", magnitude: "1_000", label: "K"}})
"45.68 K"
Scales a value representing a count in ones into a larger unit if appropriate
Examples
iex> {value, unit} = Benchee.Conversion.Count.scale(4_321.09)
iex> value
4.32109
iex> unit.name
:thousand
iex> {value, unit} = Benchee.Conversion.Count.scale(0.0045)
iex> value
0.0045
iex> unit.name
:one
Scales a value representing a count in ones into a specified unit
Examples
iex> Benchee.Conversion.Count.scale(12345, :one)
12345.0
iex> Benchee.Conversion.Count.scale(12345, :thousand)
12.345
iex> Benchee.Conversion.Count.scale(12345, :billion)
1.2345e-5
iex> Benchee.Conversion.Count.scale(12345, :million)
0.012345