mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-02 17:11:28 +00:00
Change the structure of everything to remove Manager trait.
Manager is now a simple struct, that no longer stores the results, but instead takes in a Vec<ExportEntry> and has all exporters write from this collection. Benchmark and run both return their results, no more mut manager. Change f64 in ExportEntry to hyperfine::internal::Second. Remove multiple export files for a single type.
This commit is contained in:
1 parent
c4688a7386
commit
7c7277777a
3 files changed
+40
-61
No files matched your search
+17
-22
@@ -38,7 +38,7 @@ mod hyperfine;
|
||||
|
||||
use hyperfine::internal::{CmdFailureAction, HyperfineOptions, OutputStyleOption};
|
||||
use hyperfine::benchmark::{mean_shell_spawning_time, run_benchmark};
|
||||
use hyperfine::export::{create_export_manager, ExportManager, ResultExportType};
|
||||
use hyperfine::export::{create_export_manager, ExportEntry, ResultExportType};
|
||||
|
||||
/// Print error message to stderr and terminate
|
||||
pub fn error(message: &str) -> ! {
|
||||
@@ -47,19 +47,17 @@ pub fn error(message: &str) -> ! {
|
||||
}
|
||||
|
||||
/// Runs the benchmark for the given commands
|
||||
fn run(
|
||||
commands: &Vec<&str>,
|
||||
options: &HyperfineOptions,
|
||||
exporter: &mut Option<Box<ExportManager>>,
|
||||
) -> io::Result<()> {
|
||||
fn run(commands: &Vec<&str>, options: &HyperfineOptions) -> io::Result<Vec<ExportEntry>> {
|
||||
let shell_spawning_time = mean_shell_spawning_time(&options.output_style)?;
|
||||
|
||||
let mut timing_results = vec![];
|
||||
|
||||
// Run the benchmarks
|
||||
for (num, cmd) in commands.iter().enumerate() {
|
||||
run_benchmark(num, cmd, shell_spawning_time, options, exporter)?;
|
||||
timing_results.push(run_benchmark(num, cmd, shell_spawning_time, options)?);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
Ok(timing_results)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -143,8 +141,6 @@ fn main() {
|
||||
Arg::with_name("export-csv")
|
||||
.long("export-csv")
|
||||
.takes_value(true)
|
||||
.multiple(true)
|
||||
.number_of_values(1)
|
||||
.value_name("FILE")
|
||||
.help("Export the timing results to the given file in csv format."),
|
||||
)
|
||||
@@ -180,12 +176,10 @@ fn main() {
|
||||
// Initial impl since we're only doing csv files, expand once we have multiple
|
||||
// export types. Simplest probably to do the same for each, but check for
|
||||
// None manager on later additions (JSON, Markdown, etc.)
|
||||
let mut export_manager = match matches.values_of("export-csv") {
|
||||
Some(filenames) => {
|
||||
let export_manager = match matches.value_of("export-csv") {
|
||||
Some(filename) => {
|
||||
let mut export_manager = create_export_manager();
|
||||
for filename in filenames {
|
||||
export_manager.add_exporter(&ResultExportType::Csv(filename.to_string()));
|
||||
}
|
||||
export_manager.add_exporter(&ResultExportType::Csv(filename.to_string()));
|
||||
Some(export_manager)
|
||||
}
|
||||
None => None,
|
||||
@@ -205,13 +199,14 @@ fn main() {
|
||||
}
|
||||
|
||||
let commands = matches.values_of("command").unwrap().collect();
|
||||
let res = run(&commands, &options, &mut export_manager);
|
||||
let res = run(&commands, &options);
|
||||
|
||||
if let Err(e) = res {
|
||||
error(e.description());
|
||||
}
|
||||
|
||||
if let Some(exporter) = export_manager {
|
||||
exporter.write_results().unwrap();
|
||||
match res {
|
||||
Ok(timing_results) => {
|
||||
if let Some(mut exporter) = export_manager {
|
||||
exporter.write_results(timing_results).unwrap();
|
||||
}
|
||||
}
|
||||
Err(e) => error(e.description()),
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user