Skip to content

Commit

Permalink
Handle Throughput::BytesDecimal
Browse files Browse the repository at this point in the history
Fixes the panic when encountering the relatively new throughput variant:

thread 'main' panicked at ***/criterion-0.5.1/src/benchmark_group.rsError: :316:30:
called `Result::unwrap()` on an `Err` value: Io(Os { code: 32, kind: BrokenPipe, message: "Broken pipe" })
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Caused by:
    0: Failed to parse message from Criterion.rs benchmark
    1: unknown variant `BytesDecimal`, expected `Bytes` or `Elements`
  • Loading branch information
jonasmalacofilho committed Jul 11, 2024
1 parent d4875cf commit 0d048fa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ pub struct PlotConfiguration {
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
pub enum Throughput {
Bytes(u64),
BytesDecimal(u64),
Elements(u64),
}

Expand Down
2 changes: 1 addition & 1 deletion src/message_formats/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct Throughput {
impl From<&ThroughputEnum> for Throughput {
fn from(other: &ThroughputEnum) -> Self {
match other {
ThroughputEnum::Bytes(bytes) => Throughput {
ThroughputEnum::Bytes(bytes) | ThroughputEnum::BytesDecimal(bytes) => Throughput {
per_iteration: *bytes,
unit: "bytes".to_owned(),
},
Expand Down
6 changes: 4 additions & 2 deletions src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ impl BenchmarkId {

pub fn as_number(&self) -> Option<f64> {
match self.throughput {
Some(Throughput::Bytes(n)) | Some(Throughput::Elements(n)) => Some(n as f64),
Some(Throughput::Bytes(n))
| Some(Throughput::BytesDecimal(n))
| Some(Throughput::Elements(n)) => Some(n as f64),
None => self
.value_str
.as_ref()
Expand All @@ -164,7 +166,7 @@ impl BenchmarkId {

pub fn value_type(&self) -> Option<ValueType> {
match self.throughput {
Some(Throughput::Bytes(_)) => Some(ValueType::Bytes),
Some(Throughput::Bytes(_)) | Some(Throughput::BytesDecimal(_)) => Some(ValueType::Bytes),
Some(Throughput::Elements(_)) => Some(ValueType::Elements),
None => self
.value_str
Expand Down

0 comments on commit 0d048fa

Please sign in to comment.