/ thirdparty / hyperfine / src / main.rs
main.rs
 1  #![cfg_attr(
 2      all(windows, feature = "windows_process_extensions_main_thread_handle"),
 3      feature(windows_process_extensions_main_thread_handle)
 4  )]
 5  
 6  use std::env;
 7  
 8  use benchmark::scheduler::Scheduler;
 9  use cli::get_cli_arguments;
10  use command::Commands;
11  use export::ExportManager;
12  use options::Options;
13  
14  use anyhow::Result;
15  use colored::*;
16  
17  pub mod benchmark;
18  pub mod cli;
19  pub mod command;
20  pub mod error;
21  pub mod export;
22  pub mod options;
23  pub mod outlier_detection;
24  pub mod output;
25  pub mod parameter;
26  pub mod timer;
27  pub mod util;
28  
29  fn run() -> Result<()> {
30      // Enabled ANSI colors on Windows 10
31      #[cfg(windows)]
32      colored::control::set_virtual_terminal(true).unwrap();
33  
34      let cli_arguments = get_cli_arguments(env::args_os());
35      let mut options = Options::from_cli_arguments(&cli_arguments)?;
36      let commands = Commands::from_cli_arguments(&cli_arguments)?;
37      let export_manager = ExportManager::from_cli_arguments(
38          &cli_arguments,
39          options.time_unit,
40          options.sort_order_exports,
41      )?;
42  
43      options.validate_against_command_list(&commands)?;
44  
45      let mut scheduler = Scheduler::new(&commands, &options, &export_manager);
46      scheduler.run_benchmarks()?;
47      scheduler.print_relative_speed_comparison();
48      scheduler.final_export()?;
49  
50      Ok(())
51  }
52  
53  fn main() {
54      match run() {
55          Ok(_) => {}
56          Err(e) => {
57              eprintln!("{} {:#}", "Error:".red(), e);
58              std::process::exit(1);
59          }
60      }
61  }