Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support throughput reports in bits #833

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
support throughput reports in bits
birneee committed Dec 13, 2024
commit a2666aadd70817abd199ece63906d2cec8895644
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -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`].
21 changes: 21 additions & 0 deletions src/measurement.rs
Original file line number Diff line number Diff line change
@@ -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),
}
}

1 change: 1 addition & 0 deletions src/plot/gnuplot_backend/summary.rs
Original file line number Diff line number Diff line change
@@ -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 => "",
};

1 change: 1 addition & 0 deletions src/plot/plotters_backend/summary.rs
Original file line number Diff line number Diff line change
@@ -68,6 +68,7 @@ fn draw_line_comarision_figure<XR: AsRangedCoord<Value = f64>, YR: AsRangedCoord
let input_suffix = match value_type {
ValueType::Bytes => " Size (Bytes)",
ValueType::Elements => " Size (Elements)",
ValueType::Bits => " Size (Bits)",
ValueType::Value => "",
};

5 changes: 4 additions & 1 deletion src/report.rs
Original file line number Diff line number Diff line change
@@ -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()