Skip to content
Myr

Move Exporter::unit => determine_unit_from_results

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 69d38a5 · Browse files · 2 files+20 added−25 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+20 added−25 removed

  • other:+20 added−25 removed

2 files+20 added−25 removed

modified:src/export/markdown.rs+2 added-2 removed
1use super::Exporter;1use super::{determine_unit_from_results, Exporter};2use crate::benchmark::benchmark_result::BenchmarkResult;3use crate::benchmark::relative_speed;4use crate::export::markup::MarkupFormatter;5use crate::util::units::Unit;
21 unmodified lines
27pub struct MarkdownExporter {}2829impl Exporter for MarkdownExporter {30 fn serialize(&self, results: &[BenchmarkResult], unit: Option<Unit>) -> Result<Vec<u8>> {31 let unit = self.unit(results, unit);31 let unit = determine_unit_from_results(results, unit);32 let entries = relative_speed::compute(results);33 if entries.is_none() {34 return Err(anyhow!(35 "Relative speed comparison is not available for Markdown export."
247 unmodified lines
modified:src/export/mod.rs+18 added-23 removed
17 unmodified lines
1819use anyhow::{Context, Result};20use clap::ArgMatches;2122pub fn determine_unit_from_results(results: &[BenchmarkResult], unit: Option<Unit>) -> Unit {23 return if let Some(unit) = unit {24 // Use the given unit for all entries.25 unit26 } else if let Some(first_result) = results.first() {27 // Use the first BenchmarkResult entry to determine the unit for all entries.28 format_duration_value(first_result.mean, None).129 } else {30 // Default to `Second`.31 Unit::Second32 };33}3435/// The desired form of exporter to use for a given file.36#[derive(Clone)]37pub enum ExportType {38 /// Asciidoc Table
12 unmodified lines
51/// Interface for different exporters.52trait Exporter {53 /// Export the given entries in the serialized form.54 fn serialize(&self, results: &[BenchmarkResult], unit: Option<Unit>) -> Result<Vec<u8>>;4243 fn unit(&self, results: &[BenchmarkResult], unit: Option<Unit>) -> Unit {44 return if let Some(unit) = unit {45 // Use the given unit for all entries.46 unit47 } else if let Some(first_result) = results.first() {48 // Use the first BenchmarkResult entry to determine the unit for all entries.49 format_duration_value(first_result.mean, None).150 } else {51 // Default to `Second`.52 Unit::Second53 };54 }55}5657struct ExporterWithFilename {58 exporter: Box<dyn Exporter>,
110 unmodified lines
169 },170 ];171 let unit = Some(Unit::Second);172173 let exporter = TestExporter::default();174 let markup_actual = exporter.unit(&results, unit);173 let markup_actual = determine_unit_from_results(&results, unit);174 let markup_expected = Unit::Second;175176 assert_eq!(markup_expected, markup_actual);177}
31 unmodified lines
209 },210 ];211 let unit = Some(Unit::MilliSecond);212214 let exporter = TestExporter::default();215 let markup_actual = exporter.unit(&results, unit);213 let markup_actual = determine_unit_from_results(&results, unit);214 let markup_expected = Unit::MilliSecond;215216 assert_eq!(markup_expected, markup_actual);217}
31 unmodified lines
249 },250 ];251 let unit = None;252255 let exporter = TestExporter::default();256 let markup_actual = exporter.unit(&results, unit);253 let markup_actual = determine_unit_from_results(&results, unit);254 let markup_expected = Unit::Second;255256 assert_eq!(markup_expected, markup_actual);257}
31 unmodified lines
289 },290 ];291 let unit = None;292296 let exporter = TestExporter::default();297 let markup_actual = exporter.unit(&results, unit);293 let markup_actual = determine_unit_from_results(&results, unit);294 let markup_expected = Unit::MilliSecond;295296 assert_eq!(markup_expected, markup_actual);297}
3 unmodified lines
301fn test_markup_table_unit_default_s() {302 let results: Vec<BenchmarkResult> = vec![];303 let unit = None;304309 let exporter = TestExporter::default();310 let markup_actual = exporter.unit(&results, unit);305 let markup_actual = determine_unit_from_results(&results, unit);306 let markup_expected = Unit::Second;307308 assert_eq!(markup_expected, markup_actual);309}