Skip to content
Myr

markup.rs

This file

Path

src/export/markup.rs

111 lines · 3.4 KiB · Rust

Last changed by

Export selected metrics side by side in CSVDavid Peterbefore adoption067ee70

History of this file

Take it

The walk stopped after 200 commits: lines older than 0f91d0c 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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

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 serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

lines 77–79why, one step back
77}
7879impl<T: MarkupExporter> Exporter for T {

Export selected metrics side by side in CSVDavid Peterbefore adoption067ee70

lines 80–85why, one step back
80 fn serialize(
81 &self,82 results: &[BenchmarkResult],83 metrics: &[MetricSelection],84 ) -> Result<Vec<u8>> {85 let primary = metrics[0];

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

lines 86–109why, one step back
86 let stats: Vec<_> = results
87 .iter()88 .map(|result| {89 primary90 .metric91 .summarize(&result.measurements)92 .with_context(|| {93 format!(94 "Metric '{}' is unavailable for '{}'",95 primary.metric.name(),96 result.get_name()97 )98 })99 })100 .collect::<Result<_>>()?;101 // Use one common unit, avoiding an unscaled column if the reference is zero.102 let mean = stats103 .iter()104 .find(|stats| stats.mean != 0.0)105 .map_or(0.0, |stats| stats.mean);106 let unit = primary.display_unit(mean);107 Ok(self108 .table_results(results, &stats, primary, unit)109 .into_bytes())

Bump serde from 1.0.174 to 1.0.179dependabot[bot]before adoption0f91d0c

lines 110–111why, one step back
110 }
111}