Skip to content
Myr

Do not use value_in for CSV export

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Peter · committed by David Peter · parent ebf1273 · Browse files · 2 files+17 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+17 added−13 removed

  • other:+17 added−13 removed

2 files+17 added−13 removed

modified:src/export/csv.rs+7 added-5 removed
3 unmodified lines
45use super::Exporter;6use crate::benchmark::benchmark_result::BenchmarkResult;7use crate::options::SortOrder;8use crate::quantity::{second, TimeQuantity, TimeUnit};8use crate::quantity::{TimeQuantity, TimeUnit};910use anyhow::Result;1112#[derive(Default)]
38 unmodified lines
51 res.measurements.time_system_mean(),52 res.measurements.min(),53 res.measurements.max(),54 ] {55 fields.push(Cow::Owned(f.value_in(second).to_string().into_bytes()))55 fields.push(Cow::Owned(56 f.format(CSV_UNIT, Some(CSV_PRECISION)).into_bytes(),57 ))58 }59 for v in res.parameters.values() {60 fields.push(Cow::Borrowed(v.value.as_bytes()))61 }
7 unmodified lines
69#[test]70fn test_csv() {71 use crate::benchmark::benchmark_result::Parameter;72 use crate::benchmark::measurement::{Measurement, Measurements};71 use crate::quantity::{byte, Information, Time, TimeQuantity};73 use crate::quantity::{byte, second, Information, Time, TimeQuantity};7475 use std::collections::BTreeMap;76 use std::process::ExitStatus;77
98 unmodified lines
176 .unwrap();177178 insta::assert_snapshot!(actual, @r#"179 command,mean,stddev,median,user,system,min,max,parameter_bar,parameter_foo178 command_a,9,2.6457513110645907,8,9,0,7,12,two,one179 command_b,18,1,18,18,0,17,19,seven,one180 command_a,9.000000,2.645751,8.000000,9.000000,0.000000,7.000000,12.000000,two,one181 command_b,18.000000,1.000000,18.000000,18.000000,0.000000,17.000000,19.000000,seven,one182 "#);183}
modified:src/quantity/mod.rs+10 added-8 removed
32 unmodified lines
33 U: si::time::Unit + Conversion<f64, T = f64>;3435 fn suitable_unit(&self) -> TimeUnit;3637 fn format(&self, u: TimeUnit, precision: Option<usize>) -> String;38 fn format_auto(&self, time_unit: Option<TimeUnit>) -> String;39 fn format_value_auto(&self, time_unit: Option<TimeUnit>) -> String;40}4141fn format_value_in(t: Time, u: TimeUnit, precision: Option<usize>) -> String {42 let precision = precision.unwrap_or_else(|| if u == TimeUnit::Second { 3 } else { 1 });43 u.format(t, precision)44}4542impl TimeQuantity for Time {43 fn value_in<U>(&self, _u: U) -> f6444 where45 U: si::time::Unit + Conversion<f64, T = f64>,
10 unmodified lines
56 TimeUnit::Second57 }58 }5960 /// Format the given time duration as a string.61 fn format(&self, u: TimeUnit, precision: Option<usize>) -> String {62 let precision = precision.unwrap_or_else(|| if u == TimeUnit::Second { 3 } else { 1 });63 u.format(*self, precision)64 }6564 /// Format the given duration as a string. The output-unit can be enforced by setting `unit` to66 /// Format the given time duration as a string. The output-unit can be enforced by setting `unit` to67 /// `Some(target_unit)`. If `unit` is `None`, it will be determined automatically.68 fn format_auto(&self, time_unit: Option<TimeUnit>) -> String {69 let time_unit = time_unit.unwrap_or_else(|| self.suitable_unit());7069 let value = format_value_in(*self, time_unit, None);71 let value = self.format(time_unit, None);7273 format!("{} {}", value, time_unit.short_name())74 }7576 /// Like `format_duration`, but returns the target unit as well.77 fn format_value_auto(&self, time_unit: Option<TimeUnit>) -> String {78 let time_unit = time_unit.unwrap_or_else(|| self.suitable_unit());7978 format_value_in(*self, time_unit, None)80 self.format(time_unit, None)81 }82}8384pub const fn const_time_from_seconds(value: f64) -> Time {
157 unmodified lines