markup.rs (hyperfine-1.14.0) | : | markup.rs (hyperfine-1.15.0) | ||
---|---|---|---|---|
skipping to change at line 18 | skipping to change at line 18 | |||
pub enum Alignment { | pub enum Alignment { | |||
Left, | Left, | |||
Right, | Right, | |||
} | } | |||
pub trait MarkupExporter { | pub trait MarkupExporter { | |||
fn table_results(&self, entries: &[BenchmarkResultWithRelativeSpeed], unit: Unit) -> String { | fn table_results(&self, entries: &[BenchmarkResultWithRelativeSpeed], unit: Unit) -> String { | |||
// prepare table header strings | // prepare table header strings | |||
let notation = format!("[{}]", unit.short_name()); | let notation = format!("[{}]", unit.short_name()); | |||
// emit header | // prepare table cells alignment | |||
let mut table = self.table_row(&[ | let cells_alignment = [ | |||
Alignment::Left, | ||||
Alignment::Right, | ||||
Alignment::Right, | ||||
Alignment::Right, | ||||
Alignment::Right, | ||||
]; | ||||
// emit table header format | ||||
let mut table = self.table_header(&cells_alignment); | ||||
// emit table header data | ||||
table.push_str(&self.table_row(&[ | ||||
"Command", | "Command", | |||
&format!("Mean {}", notation), | &format!("Mean {}", notation), | |||
&format!("Min {}", notation), | &format!("Min {}", notation), | |||
&format!("Max {}", notation), | &format!("Max {}", notation), | |||
"Relative", | "Relative", | |||
]); | ])); | |||
// emit horizontal line | // emit horizontal line | |||
table.push_str(&self.table_divider(&[ | table.push_str(&self.table_divider(&cells_alignment)); | |||
Alignment::Left, | ||||
Alignment::Right, | ||||
Alignment::Right, | ||||
Alignment::Right, | ||||
Alignment::Right, | ||||
])); | ||||
for entry in entries { | for entry in entries { | |||
let measurement = &entry.result; | let measurement = &entry.result; | |||
// prepare data row strings | // prepare data row strings | |||
let cmd_str = measurement.command.replace('|', "\\|"); | let cmd_str = measurement.command.replace('|', "\\|"); | |||
let mean_str = format_duration_value(measurement.mean, Some(unit)).0 ; | let mean_str = format_duration_value(measurement.mean, Some(unit)).0 ; | |||
let stddev_str = if let Some(stddev) = measurement.stddev { | let stddev_str = if let Some(stddev) = measurement.stddev { | |||
format!(" ± {}", format_duration_value(stddev, Some(unit)).0) | format!(" ± {}", format_duration_value(stddev, Some(unit)).0) | |||
} else { | } else { | |||
"".into() | "".into() | |||
skipping to change at line 67 | skipping to change at line 73 | |||
// prepare table row entries | // prepare table row entries | |||
table.push_str(&self.table_row(&[ | table.push_str(&self.table_row(&[ | |||
&self.command(&cmd_str), | &self.command(&cmd_str), | |||
&format!("{}{}", mean_str, stddev_str), | &format!("{}{}", mean_str, stddev_str), | |||
&min_str, | &min_str, | |||
&max_str, | &max_str, | |||
&format!("{}{}", rel_str, rel_stddev_str), | &format!("{}{}", rel_str, rel_stddev_str), | |||
])) | ])) | |||
} | } | |||
// emit table footer format | ||||
table.push_str(&self.table_footer(&cells_alignment)); | ||||
table | table | |||
} | } | |||
fn table_row(&self, cells: &[&str]) -> String; | fn table_row(&self, cells: &[&str]) -> String; | |||
fn table_divider(&self, cell_aligmnents: &[Alignment]) -> String; | fn table_divider(&self, cell_aligmnents: &[Alignment]) -> String; | |||
fn table_header(&self, _cell_aligmnents: &[Alignment]) -> String { | ||||
"".to_string() | ||||
} | ||||
fn table_footer(&self, _cell_aligmnents: &[Alignment]) -> String { | ||||
"".to_string() | ||||
} | ||||
fn command(&self, size: &str) -> String; | fn command(&self, size: &str) -> String; | |||
} | } | |||
fn determine_unit_from_results(results: &[BenchmarkResult]) -> Unit { | fn determine_unit_from_results(results: &[BenchmarkResult]) -> Unit { | |||
if let Some(first_result) = results.first() { | if let Some(first_result) = results.first() { | |||
// Use the first BenchmarkResult entry to determine the unit for all ent ries. | // Use the first BenchmarkResult entry to determine the unit for all ent ries. | |||
format_duration_value(first_result.mean, None).1 | format_duration_value(first_result.mean, None).1 | |||
} else { | } else { | |||
// Default to `Second`. | // Default to `Second`. | |||
Unit::Second | Unit::Second | |||
} | } | |||
} | } | |||
impl<T: MarkupExporter> Exporter for T { | impl<T: MarkupExporter> Exporter for T { | |||
fn serialize(&self, results: &[BenchmarkResult], unit: Option<Unit>) -> Resu lt<Vec<u8>> { | fn serialize(&self, results: &[BenchmarkResult], unit: Option<Unit>) -> Resu lt<Vec<u8>> { | |||
let unit = unit.unwrap_or_else(|| determine_unit_from_results(&results)) ; | let unit = unit.unwrap_or_else(|| determine_unit_from_results(results)); | |||
let entries = relative_speed::compute(results); | let entries = relative_speed::compute(results); | |||
if entries.is_none() { | if entries.is_none() { | |||
return Err(anyhow!( | return Err(anyhow!( | |||
"Relative speed comparison is not available for markup exporter. " | "Relative speed comparison is not available for markup exporter. " | |||
)); | )); | |||
} | } | |||
let table = self.table_results(&entries.unwrap(), unit); | let table = self.table_results(&entries.unwrap(), unit); | |||
Ok(table.as_bytes().to_vec()) | Ok(table.as_bytes().to_vec()) | |||
} | } | |||
End of changes. 6 change blocks. | ||||
11 lines changed or deleted | 28 lines changed or added |