Skip to content

Commit deb0eb0

Browse files
authored
feat: support throughput reports in bits (#833)
1 parent d4fd7cc commit deb0eb0

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,11 @@ pub enum Throughput {
12741274
/// collection, but could also be the number of lines of input text or the number of values to
12751275
/// parse.
12761276
Elements(u64),
1277+
1278+
/// Measure throughput in terms of bits/second. The value should be the number of bits
1279+
/// processed by one iteration of the benchmarked code. Typically, this would be the number of
1280+
/// bits transferred by a networking function.
1281+
Bits(u64),
12771282
}
12781283

12791284
/// Axis scaling type. Specified via [`PlotConfiguration::summary_scale`].

src/measurement.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,26 @@ impl DurationFormatter {
166166

167167
unit
168168
}
169+
170+
fn bits_per_second(&self, bits: f64, typical: f64, values: &mut [f64]) -> &'static str {
171+
let bits_per_second = bits * (1e9 / typical);
172+
let (denominator, unit) = if bits_per_second < 1000.0 {
173+
(1.0, " b/s")
174+
} else if bits_per_second < 1000.0 * 1000.0 {
175+
(1000.0, "Kb/s")
176+
} else if bits_per_second < 1000.0 * 1000.0 * 1000.0 {
177+
(1000.0 * 1000.0, "Mb/s")
178+
} else {
179+
(1000.0 * 1000.0 * 1000.0, "Gb/s")
180+
};
181+
182+
for val in values {
183+
let bits_per_second = bits * (1e9 / *val);
184+
*val = bits_per_second / denominator;
185+
}
186+
187+
unit
188+
}
169189
}
170190
impl ValueFormatter for DurationFormatter {
171191
fn scale_throughputs(
@@ -180,6 +200,7 @@ impl ValueFormatter for DurationFormatter {
180200
self.bytes_per_second_decimal(bytes as f64, typical, values)
181201
}
182202
Throughput::Elements(elems) => self.elements_per_second(elems as f64, typical, values),
203+
Throughput::Bits(bits) => self.bits_per_second(bits as f64, typical, values),
183204
}
184205
}
185206

src/plot/gnuplot_backend/summary.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub fn line_comparison(
4747
let input_suffix = match value_type {
4848
ValueType::Bytes => " Size (Bytes)",
4949
ValueType::Elements => " Size (Elements)",
50+
ValueType::Bits => " Size (Bits)",
5051
ValueType::Value => "",
5152
};
5253

src/plot/plotters_backend/summary.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ fn draw_line_comarision_figure<XR: AsRangedCoord<Value = f64>, YR: AsRangedCoord
6868
let input_suffix = match value_type {
6969
ValueType::Bytes => " Size (Bytes)",
7070
ValueType::Elements => " Size (Elements)",
71+
ValueType::Bits => " Size (Bits)",
7172
ValueType::Value => "",
7273
};
7374

src/report.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ impl<'a> MeasurementData<'a> {
5959
pub enum ValueType {
6060
Bytes,
6161
Elements,
62+
Bits,
6263
Value,
6364
}
6465

@@ -176,7 +177,8 @@ impl BenchmarkId {
176177
match self.throughput {
177178
Some(Throughput::Bytes(n))
178179
| Some(Throughput::Elements(n))
179-
| Some(Throughput::BytesDecimal(n)) => Some(n as f64),
180+
| Some(Throughput::BytesDecimal(n))
181+
| Some(Throughput::Bits(n)) => Some(n as f64),
180182
None => self
181183
.value_str
182184
.as_ref()
@@ -189,6 +191,7 @@ impl BenchmarkId {
189191
Some(Throughput::Bytes(_)) => Some(ValueType::Bytes),
190192
Some(Throughput::BytesDecimal(_)) => Some(ValueType::Bytes),
191193
Some(Throughput::Elements(_)) => Some(ValueType::Elements),
194+
Some(Throughput::Bits(_)) => Some(ValueType::Bits),
192195
None => self
193196
.value_str
194197
.as_ref()

0 commit comments

Comments
 (0)