Skip to content
Myr

csv.rs

This file

Path

src/export/csv.rs

123 lines · 3.6 KiB · Rust

Last changed by

Simplify CSV testsDavid Peterbefore adoption0d2e3a4

History of this file

Take it

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

Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70

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;

Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70

lines 8–15why, one step back
8use crate::util::units::Unit;
910use anyhow::Result;1112#[derive(Default)]13pub struct CsvExporter {}1415impl Exporter for CsvExporter {

Add new --sort optionDavid Peterbefore adoptionac617c8

lines 16–21why, one step back
16 fn serialize(
17 &self,18 results: &[BenchmarkResult],19 _unit: Option<Unit>,20 _sort_order: SortOrder,21 ) -> Result<Vec<u8>> {

Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70

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

style: simplify string interpolationHamir Mahalbefore adoptionef12632

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

Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70

lines 35–69why, one step back
35 }
36 }37 writer.write_record(headers)?;38 }3940 for res in results {41 let mut fields = vec![Cow::Borrowed(res.command.as_bytes())];42 for f in &[43 res.mean,44 res.stddev.unwrap_or(0.0),45 res.median,46 res.user,47 res.system,48 res.min,49 res.max,50 ] {51 fields.push(Cow::Owned(f.to_string().into_bytes()))52 }53 for v in res.parameters.values() {54 fields.push(Cow::Borrowed(v.as_bytes()))55 }56 writer.write_record(fields)?;57 }5859 Ok(writer.into_inner()?)60 }61}6263#[test]64fn test_csv() {65 use std::collections::BTreeMap;66 let exporter = CsvExporter::default();6768 let results = vec![69 BenchmarkResult {

Simplify CSV testsDavid Peterbefore adoption0d2e3a4

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

Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70

lines 72–79why, one step back
72 mean: 1.0,
73 stddev: Some(2.0),74 median: 1.0,75 user: 3.0,76 system: 4.0,77 min: 5.0,78 max: 6.0,79 times: Some(vec![7.0, 8.0, 9.0]),

Initial work on tracking memory usageDavid Peterbefore adoption6556b2b

line 80why, one step back
80 memory_usage_byte: None,

Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70

lines 81–89why, one step back
81 exit_codes: vec![Some(0), Some(0), Some(0)],
82 parameters: {83 let mut params = BTreeMap::new();84 params.insert("foo".into(), "one".into());85 params.insert("bar".into(), "two".into());86 params87 },88 },89 BenchmarkResult {

Simplify CSV testsDavid Peterbefore adoption0d2e3a4

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

Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70

lines 92–99why, one step back
92 mean: 11.0,
93 stddev: Some(12.0),94 median: 11.0,95 user: 13.0,96 system: 14.0,97 min: 15.0,98 max: 16.5,99 times: Some(vec![17.0, 18.0, 19.0]),

Initial work on tracking memory usageDavid Peterbefore adoption6556b2b

line 100why, one step back
100 memory_usage_byte: None,

Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70

lines 101–109why, one step back
101 exit_codes: vec![Some(0), Some(0), Some(0)],
102 parameters: {103 let mut params = BTreeMap::new();104 params.insert("foo".into(), "one".into());105 params.insert("bar".into(), "seven".into());106 params107 },108 },109 ];

Move more tests to instaDavid Peterbefore adoptionda399ab

lines 110–111why, one step back
110
111 let actual = String::from_utf8(

Add new --sort optionDavid Peterbefore adoptionac617c8

lines 112–116why, one step back
112 exporter
113 .serialize(&results, Some(Unit::Second), SortOrder::Command)114 .unwrap(),115 )116 .unwrap();

Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70

line 117why, one step back
117

Move more tests to instaDavid Peterbefore adoptionda399ab

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

Simplify CSV testsDavid Peterbefore adoption0d2e3a4

lines 120–121why, one step back
120 command_a,1,2,1,3,4,5,6,two,one
121 command_b,11,12,11,13,14,15,16.5,seven,one

Move more tests to instaDavid Peterbefore adoptionda399ab

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

Bump rust_decimal from 1.25.0 to 1.26.1dependabot[bot]before adoptiona596c70

line 123why, one step back
123}