Benchee v0.99.0 Benchee.Conversion.Memory View Source
Unit scaling for memory converting from bytes to kilobytes and others.
Only benchee plugins should use this code.
Link to this section Summary
Functions
The most basic unit in which memory occur, byte
Finds the best unit for a list of memory units. 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, :kilobyte}
Scales a memory value in bytes into a larger unit if appropriate
Scales a memory value in bytes into a value in the specified unit
Get a unit by its atom representation. If handed already a %Unit{} struct it just returns it
Link to this section Types
any_unit()
View Source
any_unit() :: unit_atom() | Benchee.Conversion.Unit.t()
any_unit() :: unit_atom() | Benchee.Conversion.Unit.t()
unit_atom()
View Source
unit_atom() :: :byte | :kilobyte | :megabyte | :gigabyte | :terabyte
unit_atom() :: :byte | :kilobyte | :megabyte | :gigabyte | :terabyte
Link to this section Functions
base_unit() View Source
The most basic unit in which memory occur, byte.
Examples
iex> Benchee.Conversion.Memory.base_unit.name
:byte
best(list, opts \\ [strategy: :best]) View Source
Finds the best unit for a list of memory units. 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.
Pass [strategy: :best]
to always return the most frequent unit in the list.
Pass [strategy: :none]
to always return :byte.
Examples
iex> Benchee.Conversion.Memory.best([23, 23_000, 34_000, 2_340_000]).name
:kilobyte
iex> Benchee.Conversion.Memory.best([23, 23_000, 34_000, 2_340_000, 3_450_000]).name
:megabyte
iex> Benchee.Conversion.Memory.best([23, 23_000, 34_000, 2_340_000], strategy: :smallest).name
:byte
iex> Benchee.Conversion.Memory.best([23, 23_000, 34_000, 2_340_000], strategy: :largest).name
:megabyte
convert(number_and_unit, desired_unit)
View Source
convert({number(), any_unit()}, any_unit()) ::
Benchee.Conversion.Scale.scaled_number()
convert({number(), any_unit()}, any_unit()) :: Benchee.Conversion.Scale.scaled_number()
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.Memory.convert({1024, :kilobyte}, :megabyte) iex> value 1.0 iex> unit.name :megabyte
iex> current_unit = Benchee.Conversion.Memory.unit_for :kilobyte iex> {value, unit} = Benchee.Conversion.Memory.convert({1024, current_unit}, :megabyte) iex> value 1.0 iex> unit.name :megabyte
format(memory) View Source
Formats a number as a string, with a unit label. To specify the unit, pass
a tuple of {value, unit_atom}
like {1_234, :kilobyte}
Examples
iex> Benchee.Conversion.Memory.format(45_678.9)
"44.61 KB"
iex> Benchee.Conversion.Memory.format(45.6789)
"45.68 B"
iex> Benchee.Conversion.Memory.format({45.6789, :kilobyte})
"45.68 KB"
iex> Benchee.Conversion.Memory.format {45.6789,
...> %Benchee.Conversion.Unit{
...> long: "Kilobytes", magnitude: 1024, label: "KB"}
...> }
"45.68 KB"
scale(memory) View Source
Scales a memory value in bytes into a larger unit if appropriate
Examples
iex> {value, unit} = Benchee.Conversion.Memory.scale(1) iex> value 1.0 iex> unit.name :byte
iex> {value, unit} = Benchee.Conversion.Memory.scale(1_234) iex> value 1.205078125 iex> unit.name :kilobyte
iex> {value, unit} = Benchee.Conversion.Memory.scale(11_234_567_890.123) iex> value 10.463006692121736 iex> unit.name :gigabyte
iex> {value, unit} = Benchee.Conversion.Memory.scale(1_111_234_567_890.123) iex> value 1.0106619519229962 iex> unit.name :terabyte
scale(count, unit) View Source
Scales a memory value in bytes into a value in the specified unit
Examples
iex> Benchee.Conversion.Memory.scale(12345, :kilobyte)
12.0556640625
iex> Benchee.Conversion.Memory.scale(12345, :megabyte)
0.011773109436035156
iex> Benchee.Conversion.Memory.scale(123_456_789, :gigabyte)
0.11497809458523989
unit_for(unit) View Source
Get a unit by its atom representation. If handed already a %Unit{} struct it just returns it.
Examples
iex> Benchee.Conversion.Memory.unit_for :gigabyte
%Benchee.Conversion.Unit{
name: :gigabyte,
magnitude: 1_073_741_824,
label: "GB",
long: "Gigabytes"
}
iex> Benchee.Conversion.Memory.unit_for(%Benchee.Conversion.Unit{
...> name: :gigabyte,
...> magnitude: 1_073_741_824,
...> label: "GB",
...> long: "Gigabytes"
...>})
%Benchee.Conversion.Unit{
name: :gigabyte,
magnitude: 1_073_741_824,
label: "GB",
long: "Gigabytes"
}