SortOrder field

This commit is contained in:
David Peter
2024-12-29 14:07:21 +01:00
committed by David Peter
parent 0705d6c7d0
commit 038f369420
3 changed files with 24 additions and 18 deletions
+7 -8
View File
@@ -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<Vec<BenchmarkResult>> {
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)?;
+12 -9
View File
@@ -64,19 +64,24 @@ struct ExporterWithTarget {
}
/// Handles the management of multiple file exporters.
#[derive(Default)]
pub struct ExportManager {
exporters: Vec<ExporterWithTarget>,
time_unit: Option<Unit>,
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<Unit>) -> Result<Self> {
pub fn from_cli_arguments(
matches: &ArgMatches,
time_unit: Option<Unit>,
sort_order: SortOrder,
) -> Result<Self> {
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) => {
+5 -1
View File
@@ -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)?;