Skip to content
Myr

csv.rs

This file

Path

src/export/csv.rs

185 lines · 6.5 KiB · Rust

Last changed by

Merge pull request #972 from sharkdp/codex/csv-quantity-formattingDavid Peterbefore adoption683885a

History of this file

Take it

The walk stopped after 200 commits: lines older than ca9e29a point at it.

Fix pipeline!David Peterbefore adoptionca9e29a

lines 1–6why, one step back
1use std::borrow::Cow;
23use csv::WriterBuilder;45use super::Exporter;6use crate::benchmark::benchmark_result::BenchmarkResult;

Add new --sort optionDavid Peterbefore adoptionac617c8

line 7why, one step back
7use crate::options::SortOrder;

Merge pull request #972 from sharkdp/codex/csv-quantity-formattingDavid Peterbefore adoption683885a

line 8why, one step back
8use crate::quantity::{FormatQuantity, TimeUnit};

Fix pipeline!David Peterbefore adoptionca9e29a

lines 9–15why, one step back
9
10use anyhow::Result;1112#[derive(Default)]13pub struct CsvExporter {}1415impl Exporter for CsvExporter {

Add new --sort optionDavid Peterbefore adoptionac617c8

lines 16–18why, one step back
16 fn serialize(
17 &self,18 results: &[BenchmarkResult],

Merge pull request #962 from sharkdp/codex/quantity-module-layoutDavid Peterbefore adoptionecf8a24

line 19why, one step back
19 _unit: Option<TimeUnit>,

Add new --sort optionDavid Peterbefore adoptionac617c8

lines 20–21why, one step back
20 _sort_order: SortOrder,
21 ) -> Result<Vec<u8>> {

Merge pull request #972 from sharkdp/codex/csv-quantity-formattingDavid Peterbefore adoption683885a

line 22why, one step back
22 const CSV_UNIT: TimeUnit = TimeUnit::Second;

Merge pull request #966 from sharkdp/codex/csv-six-decimalsDavid Peterbefore adoption430dc5e

lines 23–24why, one step back
23 const CSV_PRECISION: usize = 6;
24

Fix pipeline!David Peterbefore adoptionca9e29a

lines 25–36why, one step back
25 let mut writer = WriterBuilder::new().from_writer(vec![]);
2627 {28 let mut headers: Vec<Cow<[u8]>> = [29 // The list of times and exit codes cannot be exported to the CSV file - omit them.30 "command", "mean", "stddev", "median", "user", "system", "min", "max",31 ]32 .iter()33 .map(|x| Cow::Borrowed(x.as_bytes()))34 .collect();35 if let Some(res) = results.first() {36 for param_name in res.parameters.keys() {

style: simplify string interpolationHamir Mahalbefore adoptionef12632

line 37why, one step back
37 headers.push(Cow::Owned(format!("parameter_{param_name}").into_bytes()));

Fix pipeline!David Peterbefore adoptionca9e29a

lines 38–45why, one step back
38 }
39 }40 writer.write_record(headers)?;41 }4243 for res in results {44 let mut fields = vec![Cow::Borrowed(res.command.as_bytes())];45 for f in &[

Merge pull request #972 from sharkdp/codex/csv-quantity-formattingDavid Peterbefore adoption683885a

lines 46–52why, one step back
46 res.mean_wall_clock_time(),
47 res.measurements.stddev().unwrap_or_default(),48 res.measurements.median(),49 res.measurements.time_user_mean(),50 res.measurements.time_system_mean(),51 res.measurements.min(),52 res.measurements.max(),

Fix pipeline!David Peterbefore adoptionca9e29a

line 53why, one step back
53 ] {

Merge pull request #972 from sharkdp/codex/csv-quantity-formattingDavid Peterbefore adoption683885a

lines 54–57why, one step back
54 fields.push(Cow::Owned(
55 f.format_with_precision(CSV_UNIT, CSV_PRECISION)56 .into_bytes(),57 ))

Fix pipeline!David Peterbefore adoptionca9e29a

lines 58–59why, one step back
58 }
59 for v in res.parameters.values() {

Merge pull request #968 from sharkdp/codex/parameter-metadataDavid Peterbefore adoption05de077

line 60why, one step back
60 fields.push(Cow::Borrowed(v.value.as_bytes()))

Fix pipeline!David Peterbefore adoptionca9e29a

lines 61–70why, one step back
61 }
62 writer.write_record(fields)?;63 }6465 Ok(writer.into_inner()?)66 }67}6869#[test]70fn test_csv() {

Merge pull request #968 from sharkdp/codex/parameter-metadataDavid Peterbefore adoption05de077

line 71why, one step back
71 use crate::benchmark::benchmark_result::Parameter;

Merge pull request #969 from sharkdp/codex/result-measurementsDavid Peterbefore adoptione689520

lines 72–74why, one step back
72 use crate::benchmark::measurement::{Measurement, Measurements};
73 use crate::quantity::{byte, second, Information, Time, Zero};74

Fix pipeline!David Peterbefore adoptionca9e29a

line 75why, one step back
75 use std::collections::BTreeMap;

Merge pull request #969 from sharkdp/codex/result-measurementsDavid Peterbefore adoptione689520

lines 76–77why, one step back
76 use std::process::ExitStatus;
77

Fix pipeline!David Peterbefore adoptionca9e29a

lines 78–81why, one step back
78 let exporter = CsvExporter::default();
7980 let results = vec![81 BenchmarkResult {

Simplify CSV testsDavid Peterbefore adoption0d2e3a4

lines 82–83why, one step back
82 command: String::from("command_a"),
83 command_with_unused_parameters: String::from("command_a"),

Merge pull request #969 from sharkdp/codex/result-measurementsDavid Peterbefore adoptione689520

lines 84–106why, one step back
84 measurements: Measurements::new(vec![
85 Measurement {86 time_wall_clock: Time::new::<second>(7.0),87 time_user: Time::new::<second>(7.0),88 time_system: Time::zero(),89 peak_memory_usage: Information::new::<byte>(1024.),90 exit_status: ExitStatus::default(),91 },92 Measurement {93 time_wall_clock: Time::new::<second>(8.0),94 time_user: Time::new::<second>(8.0),95 time_system: Time::zero(),96 peak_memory_usage: Information::new::<byte>(1024.),97 exit_status: ExitStatus::default(),98 },99 Measurement {100 time_wall_clock: Time::new::<second>(12.0),101 time_user: Time::new::<second>(12.0),102 time_system: Time::zero(),103 peak_memory_usage: Information::new::<byte>(1024.),104 exit_status: ExitStatus::default(),105 },106 ]),

Fix pipeline!David Peterbefore adoptionca9e29a

lines 107–108why, one step back
107 parameters: {
108 let mut params = BTreeMap::new();

Merge pull request #968 from sharkdp/codex/parameter-metadataDavid Peterbefore adoption05de077

lines 109–122why, one step back
109 params.insert(
110 "foo".into(),111 Parameter {112 value: "one".into(),113 is_unused: false,114 },115 );116 params.insert(117 "bar".into(),118 Parameter {119 value: "two".into(),120 is_unused: false,121 },122 );

Fix pipeline!David Peterbefore adoptionca9e29a

lines 123–126why, one step back
123 params
124 },125 },126 BenchmarkResult {

Simplify CSV testsDavid Peterbefore adoption0d2e3a4

lines 127–128why, one step back
127 command: String::from("command_b"),
128 command_with_unused_parameters: String::from("command_b"),

Merge pull request #969 from sharkdp/codex/result-measurementsDavid Peterbefore adoptione689520

lines 129–151why, one step back
129 measurements: Measurements::new(vec![
130 Measurement {131 time_wall_clock: Time::new::<second>(17.0),132 time_user: Time::new::<second>(17.0),133 time_system: Time::zero(),134 peak_memory_usage: Information::new::<byte>(1024.),135 exit_status: ExitStatus::default(),136 },137 Measurement {138 time_wall_clock: Time::new::<second>(18.0),139 time_user: Time::new::<second>(18.0),140 time_system: Time::zero(),141 peak_memory_usage: Information::new::<byte>(1024.),142 exit_status: ExitStatus::default(),143 },144 Measurement {145 time_wall_clock: Time::new::<second>(19.0),146 time_user: Time::new::<second>(19.0),147 time_system: Time::zero(),148 peak_memory_usage: Information::new::<byte>(1024.),149 exit_status: ExitStatus::default(),150 },151 ]),

Fix pipeline!David Peterbefore adoptionca9e29a

lines 152–153why, one step back
152 parameters: {
153 let mut params = BTreeMap::new();

Merge pull request #968 from sharkdp/codex/parameter-metadataDavid Peterbefore adoption05de077

lines 154–167why, one step back
154 params.insert(
155 "foo".into(),156 Parameter {157 value: "one".into(),158 is_unused: false,159 },160 );161 params.insert(162 "bar".into(),163 Parameter {164 value: "seven".into(),165 is_unused: false,166 },167 );

Fix pipeline!David Peterbefore adoptionca9e29a

lines 168–171why, one step back
168 params
169 },170 },171 ];

Move more tests to instaDavid Peterbefore adoptionda399ab

lines 172–173why, one step back
172
173 let actual = String::from_utf8(

Add new --sort optionDavid Peterbefore adoptionac617c8

line 174why, one step back
174 exporter

Merge pull request #962 from sharkdp/codex/quantity-module-layoutDavid Peterbefore adoptionecf8a24

line 175why, one step back
175 .serialize(&results, Some(TimeUnit::Second), SortOrder::Command)

Add new --sort optionDavid Peterbefore adoptionac617c8

lines 176–178why, one step back
176 .unwrap(),
177 )178 .unwrap();

Fix pipeline!David Peterbefore adoptionca9e29a

line 179why, one step back
179

Move more tests to instaDavid Peterbefore adoptionda399ab

lines 180–181why, one step back
180 insta::assert_snapshot!(actual, @r#"
181 command,mean,stddev,median,user,system,min,max,parameter_bar,parameter_foo

Merge pull request #969 from sharkdp/codex/result-measurementsDavid Peterbefore adoptione689520

lines 182–183why, one step back
182 command_a,9.000000,2.645751,8.000000,9.000000,0.000000,7.000000,12.000000,two,one
183 command_b,18.000000,1.000000,18.000000,18.000000,0.000000,17.000000,19.000000,seven,one

Move more tests to instaDavid Peterbefore adoptionda399ab

line 184why, one step back
184 "#);

Fix pipeline!David Peterbefore adoptionca9e29a

line 185why, one step back
185}