markup.rs
This file
Path
src/export/markup.rs
121 lines · 3.8 KiB · Rust
Last changed by
Move more tests to instaDavid Peterbefore adoptionda399ab
History of this fileTake it
The walk stopped after 200 commits: lines older than a596c70 point at it.
Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70
lines 1–2why, one step back1use crate::benchmark::relative_speed::BenchmarkResultWithRelativeSpeed;2use crate::benchmark::{benchmark_result::BenchmarkResult, relative_speed};Add new --sort optionDavid Peterbefore adoptionac617c8
line 3why, one step back3use crate::options::SortOrder;Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70
lines 4–7why, one step back4use crate::output::format::format_duration_value;5use crate::util::units::Unit;67use super::Exporter;Always compute relative speed comprison for export, closes #642David Peterbefore adoption9859eca
line 8why, one step back8use anyhow::Result;Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70
lines 9–13why, one step back910pub enum Alignment {11 Left,12 Right,13}Do not export intermediate results to stdout, closes #640David Peterbefore adoption2793d7b
line 14why, one step back14Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70
lines 15–34why, one step back15pub trait MarkupExporter {16 fn table_results(&self, entries: &[BenchmarkResultWithRelativeSpeed], unit: Unit) -> String {17 // prepare table header strings18 let notation = format!("[{}]", unit.short_name());1920 // prepare table cells alignment21 let cells_alignment = [22 Alignment::Left,23 Alignment::Right,24 Alignment::Right,25 Alignment::Right,26 Alignment::Right,27 ];2829 // emit table header format30 let mut table = self.table_header(&cells_alignment);3132 // emit table header data33 table.push_str(&self.table_row(&[34 "Command",style: simplify string interpolationHamir Mahalbefore adoptionef12632
lines 35–37why, one step back35 &format!("Mean {notation}"),36 &format!("Min {notation}"),37 &format!("Max {notation}"),Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70
lines 38–46why, one step back38 "Relative",39 ]));4041 // emit horizontal line42 table.push_str(&self.table_divider(&cells_alignment));4344 for entry in entries {45 let measurement = &entry.result;46 // prepare data row stringsShow unused parameters in command namesDavid Peterbefore adoptiona875276
lines 47–49why, one step back47 let cmd_str = measurement48 .command_with_unused_parameters49 .replace('|', "\\|");Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70
lines 50–58why, one step back50 let mean_str = format_duration_value(measurement.mean, Some(unit)).0;51 let stddev_str = if let Some(stddev) = measurement.stddev {52 format!(" ± {}", format_duration_value(stddev, Some(unit)).0)53 } else {54 "".into()55 };56 let min_str = format_duration_value(measurement.min, Some(unit)).0;57 let max_str = format_duration_value(measurement.max, Some(unit)).0;58 let rel_str = format!("{:.2}", entry.relative_speed);Added option to manually specify a reference to compare the results to.Jan-Eric Nitschkebefore adoption9806ed7
line 59why, one step back59 let rel_stddev_str = if entry.is_reference {Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70
lines 60–61why, one step back60 "".into()61 } else if let Some(stddev) = entry.relative_speed_stddev {style: simplify string interpolationHamir Mahalbefore adoptionef12632
line 62why, one step back62 format!(" ± {stddev:.2}")Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70
lines 63–69why, one step back63 } else {64 "".into()65 };6667 // prepare table row entries68 table.push_str(&self.table_row(&[69 &self.command(&cmd_str),style: simplify string interpolationHamir Mahalbefore adoptionef12632
line 70why, one step back70 &format!("{mean_str}{stddev_str}"),Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70
lines 71–72why, one step back71 &min_str,72 &max_str,style: simplify string interpolationHamir Mahalbefore adoptionef12632
line 73why, one step back73 &format!("{rel_str}{rel_stddev_str}"),Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70
lines 74–108why, one step back74 ]))75 }7677 // emit table footer format78 table.push_str(&self.table_footer(&cells_alignment));7980 table81 }8283 fn table_row(&self, cells: &[&str]) -> String;8485 fn table_divider(&self, cell_aligmnents: &[Alignment]) -> String;8687 fn table_header(&self, _cell_aligmnents: &[Alignment]) -> String {88 "".to_string()89 }9091 fn table_footer(&self, _cell_aligmnents: &[Alignment]) -> String {92 "".to_string()93 }9495 fn command(&self, size: &str) -> String;96}9798fn determine_unit_from_results(results: &[BenchmarkResult]) -> Unit {99 if let Some(first_result) = results.first() {100 // Use the first BenchmarkResult entry to determine the unit for all entries.101 format_duration_value(first_result.mean, None).1102 } else {103 // Default to `Second`.104 Unit::Second105 }106}107108impl<T: MarkupExporter> Exporter for T {Add new --sort optionDavid Peterbefore adoptionac617c8
lines 109–114why, one step back109 fn serialize(110 &self,111 results: &[BenchmarkResult],112 unit: Option<Unit>,113 sort_order: SortOrder,114 ) -> Result<Vec<u8>> {Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70
line 115why, one step back115 let unit = unit.unwrap_or_else(|| determine_unit_from_results(results));Add new --sort optionDavid Peterbefore adoptionac617c8
line 116why, one step back116 let entries = relative_speed::compute(results, sort_order);Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70
line 117why, one step back117Always compute relative speed comprison for export, closes #642David Peterbefore adoption9859eca
line 118why, one step back118 let table = self.table_results(&entries, unit);Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70
lines 119–121why, one step back119 Ok(table.as_bytes().to_vec())120 }121}