From a2666aadd70817abd199ece63906d2cec8895644 Mon Sep 17 00:00:00 2001 From: Benedikt Spies Date: Fri, 13 Dec 2024 11:50:33 +0100 Subject: [PATCH] support throughput reports in bits --- src/lib.rs | 5 +++++ src/measurement.rs | 21 +++++++++++++++++++++ src/plot/gnuplot_backend/summary.rs | 1 + src/plot/plotters_backend/summary.rs | 1 + src/report.rs | 5 ++++- 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 00015070..12d0076f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1275,6 +1275,11 @@ pub enum Throughput { /// collection, but could also be the number of lines of input text or the number of values to /// parse. Elements(u64), + + /// Measure throughput in terms of bits/second. The value should be the number of bits + /// processed by one iteration of the benchmarked code. Typically, this would be the number of + /// bits transferred by a networking function. + Bits(u64), } /// Axis scaling type. Specified via [`PlotConfiguration::summary_scale`]. diff --git a/src/measurement.rs b/src/measurement.rs index b74a4812..b539b594 100644 --- a/src/measurement.rs +++ b/src/measurement.rs @@ -166,6 +166,26 @@ impl DurationFormatter { unit } + + fn bits_per_second(&self, bits: f64, typical: f64, values: &mut [f64]) -> &'static str { + let bits_per_second = bits * (1e9 / typical); + let (denominator, unit) = if bits_per_second < 1000.0 { + (1.0, " b/s") + } else if bits_per_second < 1000.0 * 1000.0 { + (1000.0, "Kb/s") + } else if bits_per_second < 1000.0 * 1000.0 * 1000.0 { + (1000.0 * 1000.0, "Mb/s") + } else { + (1000.0 * 1000.0 * 1000.0, "Gb/s") + }; + + for val in values { + let bits_per_second = bits * (1e9 / *val); + *val = bits_per_second / denominator; + } + + unit + } } impl ValueFormatter for DurationFormatter { fn scale_throughputs( @@ -180,6 +200,7 @@ impl ValueFormatter for DurationFormatter { self.bytes_per_second_decimal(bytes as f64, typical, values) } Throughput::Elements(elems) => self.elements_per_second(elems as f64, typical, values), + Throughput::Bits(bits) => self.bits_per_second(bits as f64, typical, values), } } diff --git a/src/plot/gnuplot_backend/summary.rs b/src/plot/gnuplot_backend/summary.rs index d1b0195b..88e19954 100644 --- a/src/plot/gnuplot_backend/summary.rs +++ b/src/plot/gnuplot_backend/summary.rs @@ -47,6 +47,7 @@ pub fn line_comparison( let input_suffix = match value_type { ValueType::Bytes => " Size (Bytes)", ValueType::Elements => " Size (Elements)", + ValueType::Bits => " Size (Bits)", ValueType::Value => "", }; diff --git a/src/plot/plotters_backend/summary.rs b/src/plot/plotters_backend/summary.rs index 929cc843..42ebdfd2 100644 --- a/src/plot/plotters_backend/summary.rs +++ b/src/plot/plotters_backend/summary.rs @@ -68,6 +68,7 @@ fn draw_line_comarision_figure, YR: AsRangedCoord let input_suffix = match value_type { ValueType::Bytes => " Size (Bytes)", ValueType::Elements => " Size (Elements)", + ValueType::Bits => " Size (Bits)", ValueType::Value => "", }; diff --git a/src/report.rs b/src/report.rs index 93a5debd..56dc2149 100644 --- a/src/report.rs +++ b/src/report.rs @@ -59,6 +59,7 @@ impl<'a> MeasurementData<'a> { pub enum ValueType { Bytes, Elements, + Bits, Value, } @@ -176,7 +177,8 @@ impl BenchmarkId { match self.throughput { Some(Throughput::Bytes(n)) | Some(Throughput::Elements(n)) - | Some(Throughput::BytesDecimal(n)) => Some(n as f64), + | Some(Throughput::BytesDecimal(n)) + | Some(Throughput::Bits(n)) => Some(n as f64), None => self .value_str .as_ref() @@ -189,6 +191,7 @@ impl BenchmarkId { Some(Throughput::Bytes(_)) => Some(ValueType::Bytes), Some(Throughput::BytesDecimal(_)) => Some(ValueType::Bytes), Some(Throughput::Elements(_)) => Some(ValueType::Elements), + Some(Throughput::Bits(_)) => Some(ValueType::Bits), None => self .value_str .as_ref()