Skip to content
Myr

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 file

Take 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 back
1use 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 back
3
4use super::Exporter;

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 5why, one step back
5use anyhow::{Context, Result};

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 6–12why, one step back
6
7pub 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 back
13 fn table_results(
14 &self,

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

lines 15–18why, one step back
15 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 back
19 ) -> String {

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 20why, one step back
20 let notation = format!("[{}]", unit.symbol);

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 21–24why, one step back
21 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 back
25 Alignment::Left,

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

lines 26–29why, one step back
26 ];
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 back
30 &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 back
33 ]));
34 table.push_str(&self.table_divider(&cells_alignment));35

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

lines 36–44why, one step back
36 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 back
45 } else {

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 46why, one step back
46 stats.format_change_from(&summaries[0])

Bump clap_complete from 4.2.0 to 4.2.1dependabot[bot]before adoptionab5ae5f

line 47why, one step back
47 };

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

lines 48–49why, one step back
48 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 back
50 } else {

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 51why, one step back
51 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 back
52 };
53 table.push_str(&self.table_row(&[

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

lines 54–58why, one step back
54 &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 back
59 }
60 table.push_str(&self.table_footer(&cells_alignment));61 table62 }6364 fn table_row(&self, cells: &[&str]) -> String;65

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 66why, one step back
66 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 back
67

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

lines 68–69why, one step back
68 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 back
70 }
71

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

lines 72–73why, one step back
72 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 back
74 }
75

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

line 76why, one step back
76 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 back
77}
7879impl<T: MarkupExporter> Exporter for T {

Alternative performance metrics in the terminal (#986)David Peterbefore adoptionbdbfae9

lines 80–104why, one step back
80 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 back
105 }
106}