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
Provenance
- Commit
c5a2266- Tree
c130369- Author
David Peter <mail@david-peter.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
5c634c9
3 files changed+85 added−78 removed
modified:src/benchmark/mod.rs+1 added
1 pub mod relative_speed;2 pub mod result;3+pub mod schedule;4 5 use std::cmp;6 use std::process::{ExitStatus, Stdio};7 513 unmodified linesadded:src/benchmark/schedule.rs+80 added
1+use crate::options::{Options, OutputStyleOption};2+use crate::{command::Command, export::ExportManager};3+4+use super::{mean_shell_spawning_time, relative_speed, result::BenchmarkResult, run_benchmark};5+6+use anyhow::{bail, Result};7+use colored::*;8+9+pub fn write_benchmark_comparison(results: &[BenchmarkResult]) {10+ if results.len() < 2 {11+ return;12+ }13+14+ 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));16+17+ let fastest = &annotated_results[0];18+ let others = &annotated_results[1..];19+20+ println!("{}", "Summary".bold());21+ println!(" '{}' ran", fastest.result.command.cyan());22+23+ 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+}46+47+pub 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)?;54+55+ let mut timing_results = vec![];56+57+ 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+ }65+66+ // Run the benchmarks67+ for (num, cmd) in commands.iter().enumerate() {68+ timing_results.push(run_benchmark(num, cmd, shell_spawning_time, options)?);69+70+ // Export (intermediate) results71+ export_manager.write_results(&timing_results, options.time_unit)?;72+ }73+74+ // Print relative speed comparison75+ if options.output_style != OutputStyleOption::Disabled {76+ write_benchmark_comparison(&timing_results);77+ }78+79+ Ok(())80+}modified:src/main.rs+4 added-78 removed
1 use std::env;2 3 use app::get_arg_matches;4-use benchmark::result::BenchmarkResult;5-use benchmark::{mean_shell_spawning_time, relative_speed, run_benchmark};6-use command::{build_commands, Command};4+use benchmark::schedule::run_benchmarks_and_print_comparison;5+use command::build_commands;6 use export::ExportManager;8-use options::{Options, OutputStyleOption};7+use options::Options;8 10-use anyhow::{bail, Result};9+use anyhow::Result;10 use colored::*;11 12 pub mod app;13 pub mod benchmark;7 unmodified lines21 pub mod shell;22 pub mod timer;23 pub mod util;24 26-pub fn write_benchmark_comparison(results: &[BenchmarkResult]) {27- if results.len() < 2 {28- return;29- }30-31- 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));33-34- let fastest = &annotated_results[0];35- let others = &annotated_results[1..];36-37- println!("{}", "Summary".bold());38- println!(" '{}' ran", fastest.result.command.cyan());39-40- 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-}63-64-fn 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)?;71-72- let mut timing_results = vec![];73-74- 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- }82-83- // Run the benchmarks84- for (num, cmd) in commands.iter().enumerate() {85- timing_results.push(run_benchmark(num, cmd, shell_spawning_time, options)?);86-87- // Export (intermediate) results88- export_manager.write_results(&timing_results, options.time_unit)?;89- }90-91- // Print relative speed comparison92- if options.output_style != OutputStyleOption::Disabled {93- write_benchmark_comparison(&timing_results);94- }95-96- Ok(())97-}98-25 fn run() -> Result<()> {26 // Enabled ANSI colors on Windows 1027 #[cfg(windows)]28 colored::control::set_virtual_terminal(true).unwrap();18 unmodified lines