pub trait ValueFormatter {
    // Required methods
    fn scale_values(
        &self,
        typical_value: f64,
        values: &mut [f64],
    ) -> &'static str;
    fn scale_throughputs(
        &self,
        typical_value: f64,
        throughput: &Throughput,
        values: &mut [f64],
    ) -> &'static str;
    fn scale_for_machines(&self, values: &mut [f64]) -> &'static str;

    // Provided methods
    fn format_value(&self, value: f64) -> String { ... }
    fn format_throughput(&self, throughput: &Throughput, value: f64) -> String { ... }
}
Expand description

Trait providing functions to format measured values to string so that they can be displayed on the command line or in the reports. The functions of this trait take measured values in f64 form; implementors can assume that the values are of the same scale as those produced by the associated MeasuredValue (eg. if your measurement produces values in nanoseconds, the values passed to the formatter will be in nanoseconds).

Implementors are encouraged to format the values in a way that is intuitive for humans and uses the SI prefix system. For example, the format used by WallTime can display the value in units ranging from picoseconds to seconds depending on the magnitude of the elapsed time in nanoseconds.

Required Methods§

source

fn scale_values(&self, typical_value: f64, values: &mut [f64]) -> &'static str

Scale the given values to some appropriate unit and return the unit string.

The given typical value should be used to choose the unit. This function may be called multiple times with different datasets; the typical value will remain the same to ensure that the units remain consistent within a graph. The typical value will not be NaN. Values will not contain NaN as input, and the transformed values must not contain NaN.

source

fn scale_throughputs( &self, typical_value: f64, throughput: &Throughput, values: &mut [f64], ) -> &'static str

Convert the given measured values into throughput numbers based on the given throughput value, scale them to some appropriate unit, and return the unit string.

The given typical value should be used to choose the unit. This function may be called multiple times with different datasets; the typical value will remain the same to ensure that the units remain consistent within a graph. The typical value will not be NaN. Values will not contain NaN as input, and the transformed values must not contain NaN.

source

fn scale_for_machines(&self, values: &mut [f64]) -> &'static str

Scale the values and return a unit string designed for machines.

For example, this is used for the CSV file output. Implementations should modify the given values slice to apply the desired scaling (if any) and return a string representing the unit the modified values are in.

Provided Methods§

source

fn format_value(&self, value: f64) -> String

Format the value (with appropriate unit) and return it as a string.

source

fn format_throughput(&self, throughput: &Throughput, value: f64) -> String

Format the value as a throughput measurement. The value represents the measurement value; the implementor will have to calculate bytes per second, iterations per cycle, etc.

Implementors§