Benchee v0.12.0 Benchee.Conversion.Duration View Source
Unit scaling for duration converting from microseconds to minutes and others.
Link to this section Summary
Functions
The most basic unit in which measurements occur, microseconds
Finds the best unit for a list of durations. 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, :second}
Converts a value of the given unit into microseconds
Scales a duration value in microseconds into a larger unit if appropriate
Scales a duration value in microseconds 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 Functions
The most basic unit in which measurements occur, microseconds.
Examples
iex> Benchee.Conversion.Duration.base_unit.name
:microsecond
Finds the best unit for a list of durations. 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.Duration.best([23, 23_000, 34_000, 2_340_000]).name
:millisecond
iex> Benchee.Conversion.Duration.best([23, 23_000, 34_000, 2_340_000, 3_450_000]).name
:second
iex> Benchee.Conversion.Duration.best([23, 23_000, 34_000, 2_340_000], strategy: :smallest).name
:microsecond
iex> Benchee.Conversion.Duration.best([23, 23_000, 34_000, 2_340_000], strategy: :largest).name
:second
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.Duration.convert({90, :minute}, :hour) iex> value 1.5 iex> unit.name :hour
Formats a number as a string, with a unit label. To specify the unit, pass
a tuple of {value, unit_atom}
like {1_234, :second}
Examples
iex> Benchee.Conversion.Duration.format(45_678.9)
"45.68 ms"
iex> Benchee.Conversion.Duration.format(45.6789)
"45.68 μs"
iex> Benchee.Conversion.Duration.format({45.6789, :millisecond})
"45.68 ms"
iex> Benchee.Conversion.Duration.format {45.6789,
...> %Benchee.Conversion.Unit{
...> long: "Milliseconds", magnitude: 1000, label: "ms"}
...> }
"45.68 ms"
Converts a value of the given unit into microseconds
Examples
iex> Benchee.Conversion.Duration.microseconds({1.234, :second})
1_234_000.0
iex> Benchee.Conversion.Duration.microseconds({1.234, :minute})
7.404e7
iex> Benchee.Conversion.Duration.microseconds({1.234, :minute}) |> Benchee.Conversion.Duration.scale(:minute)
1.234
Scales a duration value in microseconds into a larger unit if appropriate
Examples
iex> {value, unit} = Benchee.Conversion.Duration.scale(1)
iex> value
1.0
iex> unit.name
:microsecond
iex> {value, unit} = Benchee.Conversion.Duration.scale(1_234)
iex> value
1.234
iex> unit.name
:millisecond
iex> {value, unit} = Benchee.Conversion.Duration.scale(11_234_567_890.123)
iex> value
3.1207133028119443
iex> unit.name
:hour
Scales a duration value in microseconds into a value in the specified unit
Examples
iex> Benchee.Conversion.Duration.scale(12345, :microsecond)
12345.0
iex> Benchee.Conversion.Duration.scale(12345, :millisecond)
12.345
iex> Benchee.Conversion.Duration.scale(12345, :minute)
2.0575e-4
Get a unit by its atom representation. If handed already a %Unit{} struct it just returns it.
Examples
iex> Benchee.Conversion.Duration.unit_for :hour
%Benchee.Conversion.Unit{
name: :hour,
magnitude: 3_600_000_000,
label: "h",
long: "Hours"
}
iex> Benchee.Conversion.Duration.unit_for(%Benchee.Conversion.Unit{
...> name: :hour,
...> magnitude: 3_600_000_000,
...> label: "h",
...> long: "Hours"
...>})
%Benchee.Conversion.Unit{
name: :hour,
magnitude: 3_600_000_000,
label: "h",
long: "Hours"
}