diff --git a/src/benchmark/scheduler.rs b/src/benchmark/scheduler.rs index 824788e..606d3c2 100644 --- a/src/benchmark/scheduler.rs +++ b/src/benchmark/scheduler.rs @@ -52,11 +52,7 @@ impl<'a> Scheduler<'a> { // We export results after each individual benchmark, because // we would risk losing them if a later benchmark fails. - self.export_manager.write_results( - &self.results, - self.options.sort_order_exports, - true, - )?; + self.export_manager.write_results(&self.results, true)?; } Ok(()) @@ -158,8 +154,7 @@ impl<'a> Scheduler<'a> { } pub fn final_export(&self) -> Result<()> { - self.export_manager - .write_results(&self.results, self.options.sort_order_exports, false) + self.export_manager.write_results(&self.results, false) } } @@ -176,7 +171,11 @@ fn generate_results(args: &[&'static str]) -> Result> { assert_eq!(options.executor_kind, ExecutorKind::Mock(None)); let commands = Commands::from_cli_arguments(&cli_arguments)?; - let export_manager = ExportManager::from_cli_arguments(&cli_arguments, options.time_unit)?; + let export_manager = ExportManager::from_cli_arguments( + &cli_arguments, + options.time_unit, + options.sort_order_exports, + )?; options.validate_against_command_list(&commands)?; diff --git a/src/export/mod.rs b/src/export/mod.rs index 194cad1..3947a2e 100644 --- a/src/export/mod.rs +++ b/src/export/mod.rs @@ -64,19 +64,24 @@ struct ExporterWithTarget { } /// Handles the management of multiple file exporters. -#[derive(Default)] pub struct ExportManager { exporters: Vec, time_unit: Option, + sort_order: SortOrder, } impl ExportManager { /// Build the ExportManager that will export the results specified /// in the given ArgMatches - pub fn from_cli_arguments(matches: &ArgMatches, time_unit: Option) -> Result { + pub fn from_cli_arguments( + matches: &ArgMatches, + time_unit: Option, + sort_order: SortOrder, + ) -> Result { let mut export_manager = Self { exporters: vec![], time_unit, + sort_order, }; { let mut add_exporter = |flag, exporttype| -> Result<()> { @@ -124,14 +129,12 @@ impl ExportManager { /// results are written to all file targets (to always have them up to date, even /// if a benchmark fails). In the latter case, we only print to stdout targets (in /// order not to clutter the output of hyperfine with intermediate results). - pub fn write_results( - &self, - results: &[BenchmarkResult], - sort_order: SortOrder, - intermediate: bool, - ) -> Result<()> { + pub fn write_results(&self, results: &[BenchmarkResult], intermediate: bool) -> Result<()> { for e in &self.exporters { - let content = || e.exporter.serialize(results, self.time_unit, sort_order); + let content = || { + e.exporter + .serialize(results, self.time_unit, self.sort_order) + }; match e.target { ExportTarget::File(ref filename) => { diff --git a/src/main.rs b/src/main.rs index 79acc0b..2a97505 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,7 +34,11 @@ fn run() -> Result<()> { let cli_arguments = get_cli_arguments(env::args_os()); let mut options = Options::from_cli_arguments(&cli_arguments)?; let commands = Commands::from_cli_arguments(&cli_arguments)?; - let export_manager = ExportManager::from_cli_arguments(&cli_arguments, options.time_unit)?; + let export_manager = ExportManager::from_cli_arguments( + &cli_arguments, + options.time_unit, + options.sort_order_exports, + )?; options.validate_against_command_list(&commands)?;