markup.rs
This file
Path
src/export/markup.rs
124 lines · 3.8 KiB · Rust
Last changed by
Merge pull request #969 from sharkdp/codex/result-measurementsDavid Peterbefore adoptione689520
History of this fileTake it
The walk stopped after 200 commits: lines older than ca9e29a point at it.
Fix pipeline!David Peterbefore adoptionca9e29a
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;Merge pull request #969 from sharkdp/codex/result-measurementsDavid Peterbefore adoptione689520
line 4why, one step back4use crate::quantity::{FormatQuantity, IsUnit, TimeUnit};Fix pipeline!David Peterbefore adoptionca9e29a
lines 5–6why, one step back56use super::Exporter;Always compute relative speed comprison for export, closes #642David Peterbefore adoption9859eca
line 7why, one step back7use anyhow::Result;Fix pipeline!David Peterbefore adoptionca9e29a
lines 8–12why, one step back89pub enum Alignment {10 Left,11 Right,12}Do not export intermediate results to stdout, closes #640David Peterbefore adoption2793d7b
line 13why, one step back13Fix pipeline!David Peterbefore adoptionca9e29a
line 14why, one step back14pub trait MarkupExporter {Merge pull request #962 from sharkdp/codex/quantity-module-layoutDavid Peterbefore adoptionecf8a24
lines 15–19why, one step back15 fn table_results(16 &self,17 entries: &[BenchmarkResultWithRelativeSpeed],18 unit: TimeUnit,19 ) -> String {Fix pipeline!David Peterbefore adoptionca9e29a
lines 20–37why, one step back20 // prepare table header strings21 let notation = format!("[{}]", unit.short_name());2223 // prepare table cells alignment24 let cells_alignment = [25 Alignment::Left,26 Alignment::Right,27 Alignment::Right,28 Alignment::Right,29 Alignment::Right,30 ];3132 // emit table header format33 let mut table = self.table_header(&cells_alignment);3435 // emit table header data36 table.push_str(&self.table_row(&[37 "Command",style: simplify string interpolationHamir Mahalbefore adoptionef12632
lines 38–40why, one step back38 &format!("Mean {notation}"),39 &format!("Min {notation}"),40 &format!("Max {notation}"),Fix pipeline!David Peterbefore adoptionca9e29a
lines 41–49why, one step back41 "Relative",42 ]));4344 // emit horizontal line45 table.push_str(&self.table_divider(&cells_alignment));4647 for entry in entries {48 let measurement = &entry.result;49 // prepare data row stringsShow unused parameters in command namesDavid Peterbefore adoptiona875276
lines 50–52why, one step back50 let cmd_str = measurement51 .command_with_unused_parameters52 .replace('|', "\\|");Merge pull request #969 from sharkdp/codex/result-measurementsDavid Peterbefore adoptione689520
lines 53–55why, one step back53 let mean_str = measurement.mean_wall_clock_time().format_value(unit);54 let stddev_str = if let Some(stddev) = measurement.measurements.stddev() {55 format!(" ± {}", stddev.format_value(unit))Fix pipeline!David Peterbefore adoptionca9e29a
lines 56–58why, one step back56 } else {57 "".into()58 };Merge pull request #969 from sharkdp/codex/result-measurementsDavid Peterbefore adoptione689520
lines 59–60why, one step back59 let min_str = measurement.measurements.min().format_value(unit);60 let max_str = measurement.measurements.max().format_value(unit);Fix pipeline!David Peterbefore adoptionca9e29a
line 61why, one step back61 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 62why, one step back62 let rel_stddev_str = if entry.is_reference {Fix pipeline!David Peterbefore adoptionca9e29a
lines 63–64why, one step back63 "".into()64 } else if let Some(stddev) = entry.relative_speed_stddev {style: simplify string interpolationHamir Mahalbefore adoptionef12632
line 65why, one step back65 format!(" ± {stddev:.2}")Fix pipeline!David Peterbefore adoptionca9e29a
lines 66–72why, one step back66 } else {67 "".into()68 };6970 // prepare table row entries71 table.push_str(&self.table_row(&[72 &self.command(&cmd_str),style: simplify string interpolationHamir Mahalbefore adoptionef12632
line 73why, one step back73 &format!("{mean_str}{stddev_str}"),Fix pipeline!David Peterbefore adoptionca9e29a
lines 74–75why, one step back74 &min_str,75 &max_str,style: simplify string interpolationHamir Mahalbefore adoptionef12632
line 76why, one step back76 &format!("{rel_str}{rel_stddev_str}"),Fix pipeline!David Peterbefore adoptionca9e29a
lines 77–100why, one step back77 ]))78 }7980 // emit table footer format81 table.push_str(&self.table_footer(&cells_alignment));8283 table84 }8586 fn table_row(&self, cells: &[&str]) -> String;8788 fn table_divider(&self, cell_aligmnents: &[Alignment]) -> String;8990 fn table_header(&self, _cell_aligmnents: &[Alignment]) -> String {91 "".to_string()92 }9394 fn table_footer(&self, _cell_aligmnents: &[Alignment]) -> String {95 "".to_string()96 }9798 fn command(&self, size: &str) -> String;99}100Merge pull request #962 from sharkdp/codex/quantity-module-layoutDavid Peterbefore adoptionecf8a24
line 101why, one step back101fn determine_unit_from_results(results: &[BenchmarkResult]) -> TimeUnit {Fix pipeline!David Peterbefore adoptionca9e29a
lines 102–103why, one step back102 if let Some(first_result) = results.first() {103 // Use the first BenchmarkResult entry to determine the unit for all entries.Merge pull request #969 from sharkdp/codex/result-measurementsDavid Peterbefore adoptione689520
line 104why, one step back104 first_result.mean_wall_clock_time().suitable_unit()Fix pipeline!David Peterbefore adoptionca9e29a
lines 105–106why, one step back105 } else {106 // Default to `Second`.Merge pull request #962 from sharkdp/codex/quantity-module-layoutDavid Peterbefore adoptionecf8a24
line 107why, one step back107 TimeUnit::SecondFix pipeline!David Peterbefore adoptionca9e29a
lines 108–111why, one step back108 }109}110111impl<T: MarkupExporter> Exporter for T {Add new --sort optionDavid Peterbefore adoptionac617c8
lines 112–114why, one step back112 fn serialize(113 &self,114 results: &[BenchmarkResult],Merge pull request #962 from sharkdp/codex/quantity-module-layoutDavid Peterbefore adoptionecf8a24
line 115why, one step back115 unit: Option<TimeUnit>,Add new --sort optionDavid Peterbefore adoptionac617c8
lines 116–117why, one step back116 sort_order: SortOrder,117 ) -> Result<Vec<u8>> {Fix pipeline!David Peterbefore adoptionca9e29a
line 118why, one step back118 let unit = unit.unwrap_or_else(|| determine_unit_from_results(results));Add new --sort optionDavid Peterbefore adoptionac617c8
line 119why, one step back119 let entries = relative_speed::compute(results, sort_order);Fix pipeline!David Peterbefore adoptionca9e29a
line 120why, one step back120Always compute relative speed comprison for export, closes #642David Peterbefore adoption9859eca
line 121why, one step back121 let table = self.table_results(&entries, unit);Fix pipeline!David Peterbefore adoptionca9e29a
lines 122–124why, one step back122 Ok(table.as_bytes().to_vec())123 }124}