Skip to content
Myr

New schedule module

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Peter · committed by David Peter · parent 5c634c9 · Browse files · 3 files+85 added−78 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+85 added−78 removed

  • other:+85 added−78 removed

3 files+85 added−78 removed

modified:src/benchmark/mod.rs+1 added
1pub mod relative_speed;2pub mod result;3pub mod schedule;45use std::cmp;6use std::process::{ExitStatus, Stdio};7
513 unmodified lines
added:src/benchmark/schedule.rs+80 added
1use crate::options::{Options, OutputStyleOption};2use crate::{command::Command, export::ExportManager};34use super::{mean_shell_spawning_time, relative_speed, result::BenchmarkResult, run_benchmark};56use anyhow::{bail, Result};7use colored::*;89pub fn write_benchmark_comparison(results: &[BenchmarkResult]) {10 if results.len() < 2 {11 return;12 }1314 if let Some(mut annotated_results) = relative_speed::compute(results) {15 annotated_results.sort_by(|l, r| relative_speed::compare_mean_time(l.result, r.result));1617 let fastest = &annotated_results[0];18 let others = &annotated_results[1..];1920 println!("{}", "Summary".bold());21 println!(" '{}' ran", fastest.result.command.cyan());2223 for item in others {24 println!(25 "{}{} times faster than '{}'",26 format!("{:8.2}", item.relative_speed).bold().green(),27 if let Some(stddev) = item.relative_speed_stddev {28 format!(" ± {}", format!("{:.2}", stddev).green())29 } else {30 "".into()31 },32 &item.result.command.magenta()33 );34 }35 } else {36 eprintln!(37 "{}: The benchmark comparison could not be computed as some benchmark times are zero. \38 This could be caused by background interference during the initial calibration phase \39 of hyperfine, in combination with very fast commands (faster than a few milliseconds). \40 Try to re-run the benchmark on a quiet system. If it does not help, you command is \41 most likely too fast to be accurately benchmarked by hyperfine.",42 "Note".bold().red()43 );44 }45}4647pub fn run_benchmarks_and_print_comparison(48 commands: &[Command<'_>],49 options: &Options,50 export_manager: &ExportManager,51) -> Result<()> {52 let shell_spawning_time =53 mean_shell_spawning_time(&options.shell, options.output_style, options.show_output)?;5455 let mut timing_results = vec![];5657 if let Some(preparation_command) = &options.preparation_command {58 if preparation_command.len() > 1 && commands.len() != preparation_command.len() {59 bail!(60 "The '--prepare' option has to be provided just once or N times, where N is the \61 number of benchmark commands."62 );63 }64 }6566 // Run the benchmarks67 for (num, cmd) in commands.iter().enumerate() {68 timing_results.push(run_benchmark(num, cmd, shell_spawning_time, options)?);6970 // Export (intermediate) results71 export_manager.write_results(&timing_results, options.time_unit)?;72 }7374 // Print relative speed comparison75 if options.output_style != OutputStyleOption::Disabled {76 write_benchmark_comparison(&timing_results);77 }7879 Ok(())80}
modified:src/main.rs+4 added-78 removed
1use std::env;23use app::get_arg_matches;4use benchmark::result::BenchmarkResult;5use benchmark::{mean_shell_spawning_time, relative_speed, run_benchmark};6use command::{build_commands, Command};4use benchmark::schedule::run_benchmarks_and_print_comparison;5use command::build_commands;6use export::ExportManager;8use options::{Options, OutputStyleOption};7use options::Options;810use anyhow::{bail, Result};9use anyhow::Result;10use colored::*;1112pub mod app;13pub mod benchmark;
7 unmodified lines
21pub mod shell;22pub mod timer;23pub mod util;2426pub fn write_benchmark_comparison(results: &[BenchmarkResult]) {27 if results.len() < 2 {28 return;29 }3031 if let Some(mut annotated_results) = relative_speed::compute(results) {32 annotated_results.sort_by(|l, r| relative_speed::compare_mean_time(l.result, r.result));3334 let fastest = &annotated_results[0];35 let others = &annotated_results[1..];3637 println!("{}", "Summary".bold());38 println!(" '{}' ran", fastest.result.command.cyan());3940 for item in others {41 println!(42 "{}{} times faster than '{}'",43 format!("{:8.2}", item.relative_speed).bold().green(),44 if let Some(stddev) = item.relative_speed_stddev {45 format!(" ± {}", format!("{:.2}", stddev).green())46 } else {47 "".into()48 },49 &item.result.command.magenta()50 );51 }52 } else {53 eprintln!(54 "{}: The benchmark comparison could not be computed as some benchmark times are zero. \55 This could be caused by background interference during the initial calibration phase \56 of hyperfine, in combination with very fast commands (faster than a few milliseconds). \57 Try to re-run the benchmark on a quiet system. If it does not help, you command is \58 most likely too fast to be accurately benchmarked by hyperfine.",59 "Note".bold().red()60 );61 }62}6364fn run_benchmarks_and_print_comparison(65 commands: &[Command<'_>],66 options: &Options,67 export_manager: &ExportManager,68) -> Result<()> {69 let shell_spawning_time =70 mean_shell_spawning_time(&options.shell, options.output_style, options.show_output)?;7172 let mut timing_results = vec![];7374 if let Some(preparation_command) = &options.preparation_command {75 if preparation_command.len() > 1 && commands.len() != preparation_command.len() {76 bail!(77 "The '--prepare' option has to be provided just once or N times, where N is the \78 number of benchmark commands."79 );80 }81 }8283 // Run the benchmarks84 for (num, cmd) in commands.iter().enumerate() {85 timing_results.push(run_benchmark(num, cmd, shell_spawning_time, options)?);8687 // Export (intermediate) results88 export_manager.write_results(&timing_results, options.time_unit)?;89 }9091 // Print relative speed comparison92 if options.output_style != OutputStyleOption::Disabled {93 write_benchmark_comparison(&timing_results);94 }9596 Ok(())97}9825fn run() -> Result<()> {26 // Enabled ANSI colors on Windows 1027 #[cfg(windows)]28 colored::control::set_virtual_terminal(true).unwrap();
18 unmodified lines