mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-10-12 02:22:35 +00:00
SortOrder field
This commit is contained in:
@@ -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
@@ -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
@@ -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)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user