markup.rs
This file
Path
src/export/markup.rs
106 lines · 3.3 KiB · Rust
Last changed by
Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
History of this fileTake it
The walk stopped after 200 commits: lines older than ab5ae5f point at it.
Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 1–2why, one step back1use crate::benchmark::benchmark_result::BenchmarkResult;2use crate::metric::{MetricSelection, Stats, Unit};Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 3–4why, one step back34use super::Exporter;Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 5why, one step back5use anyhow::{Context, Result};Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 6–12why, one step back67pub enum Alignment {8 Left,9 Right,10}1112pub trait MarkupExporter {Merge pull request #962 from sharkdp/codex/quantity-module-layoutDavid Peterbefore adoptionecf8a24
lines 13–14why, one step back13 fn table_results(14 &self,Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 15–18why, one step back15 results: &[BenchmarkResult],16 summaries: &[Stats],17 primary: MetricSelection,18 unit: Unit,Merge pull request #962 from sharkdp/codex/quantity-module-layoutDavid Peterbefore adoptionecf8a24
line 19why, one step back19 ) -> String {Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 20why, one step back20 let notation = format!("[{}]", unit.symbol);Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 21–24why, one step back21 let cells_alignment = [22 Alignment::Left,23 Alignment::Right,24 Alignment::Right,Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 25why, one step back25 Alignment::Left,Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 26–29why, one step back26 ];27 let mut table = self.table_header(&cells_alignment);28 table.push_str(&self.table_row(&[29 "Command",Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 30–32why, one step back30 &format!("Mean {} {notation}", primary.metric.label()),31 "Change",32 "Factor",Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 33–35why, one step back33 ]));34 table.push_str(&self.table_divider(&cells_alignment));35Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 36–44why, one step back36 for (index, (result, stats)) in results.iter().zip(summaries).enumerate() {37 let command = result.display_name.replace('|', "\\|");38 let mean = unit.format_value(stats.mean);39 let stddev = stats40 .stddev41 .map(|value| format!(" ± {}", unit.format_value(value)))42 .unwrap_or_default();43 let change = if index == 0 {44 String::new()Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 45why, one step back45 } else {Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 46why, one step back46 stats.format_change_from(&summaries[0])Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 47why, one step back47 };Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 48–49why, one step back48 let factor = if index == 0 {49 String::new()Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 50why, one step back50 } else {Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 51why, one step back51 stats.format_factor_from(&summaries[0], primary.metric)Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 52–53why, one step back52 };53 table.push_str(&self.table_row(&[Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 54–58why, one step back54 &self.command(&command),55 &format!("{mean}{stddev}"),56 &change,57 &factor,58 ]));Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 59–65why, one step back59 }60 table.push_str(&self.table_footer(&cells_alignment));61 table62 }6364 fn table_row(&self, cells: &[&str]) -> String;65Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 66why, one step back66 fn table_divider(&self, cell_alignments: &[Alignment]) -> String;Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
line 67why, one step back67Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 68–69why, one step back68 fn table_header(&self, _cell_alignments: &[Alignment]) -> String {69 String::new()Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 70–71why, one step back70 }71Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 72–73why, one step back72 fn table_footer(&self, _cell_alignments: &[Alignment]) -> String {73 String::new()Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 74–75why, one step back74 }75Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
line 76why, one step back76 fn command(&self, command: &str) -> String;Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 77–79why, one step back77}7879impl<T: MarkupExporter> Exporter for T {Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9
lines 80–104why, one step back80 fn serialize(&self, results: &[BenchmarkResult], primary: MetricSelection) -> Result<Vec<u8>> {81 let stats: Vec<_> = results82 .iter()83 .map(|result| {84 primary85 .metric86 .summarize(&result.measurements)87 .with_context(|| {88 format!(89 "Metric '{}' is unavailable for '{}'",90 primary.metric.name(),91 result.get_name()92 )93 })94 })95 .collect::<Result<_>>()?;96 // Use one common unit, avoiding an unscaled column if the reference is zero.97 let mean = stats98 .iter()99 .find(|stats| stats.mean != 0.0)100 .map_or(0.0, |stats| stats.mean);101 let unit = primary.display_unit(mean);102 Ok(self103 .table_results(results, &stats, primary, unit)104 .into_bytes())Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f
lines 105–106why, one step back105 }106}