Benchee v0.12.0 Benchee.Conversion.Count View Source
Unit scaling for counts, such that 1000000 can be converted to 1 Million.
Link to this section 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
Converts a value for a specified %Unit or unit atom and converts it to the equivalent of another unit of measure
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. If handed already a %Unit{} struct it just returns it
Link to this section 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
Converts a value for a specified %Unit or unit atom and converts it to the equivalent of another unit of measure.
Examples
iex> {value, unit} = Benchee.Conversion.Count.convert({2500, :thousand}, :million) iex> value 2.5 iex> unit.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
Get a unit by its atom representation. If handed already a %Unit{} struct it just returns it.
Examples
iex> Benchee.Conversion.Count.unit_for :thousand
%Benchee.Conversion.Unit{
name: :thousand,
magnitude: 1_000,
label: "K",
long: "Thousand"
}
iex> Benchee.Conversion.Count.unit_for(%Benchee.Conversion.Unit{
...> name: :thousand,
...> magnitude: 1_000,
...> label: "K",
...> long: "Thousand"
...>})
%Benchee.Conversion.Unit{
name: :thousand,
magnitude: 1_000,
label: "K",
long: "Thousand"
}