Move benchmark comparison to main.rs
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 eb31e0f · Browse files · 2 files·+36 added−38 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+36 added−38 removed
- other:+36 added−38 removed
Provenance
- Commit
d5a2590- Tree
d556bd1- Author
David Peter <mail@david-peter.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
eb31e0f
2 files changed+36 added−38 removed
modified:src/internal.rs+1 added-37 removed
1 use std::cmp::Ordering;2 use std::iter::Iterator;3 4-use colored::*;5-4 use crate::benchmark_result::BenchmarkResult;5 use crate::units::{Scalar, Second};6 7 /// Threshold for warning about fast execution time22 unmodified lines30 pub relative_speed_stddev: Scalar,31 pub is_fastest: bool,32 }33 36-fn compare_mean_time(l: &BenchmarkResult, r: &BenchmarkResult) -> Ordering {34+pub fn compare_mean_time(l: &BenchmarkResult, r: &BenchmarkResult) -> Ordering {35 l.mean.partial_cmp(&r.mean).unwrap_or(Ordering::Equal)36 }37 38 pub fn compute_relative_speed(31 unmodified lines70 .collect(),71 )72 }73 76-pub fn write_benchmark_comparison(results: &[BenchmarkResult]) {77- if results.len() < 2 {78- return;79- }80-81- if let Some(mut annotated_results) = compute_relative_speed(results) {82- annotated_results.sort_by(|l, r| compare_mean_time(l.result, r.result));83-84- let fastest = &annotated_results[0];85- let others = &annotated_results[1..];86-87- println!("{}", "Summary".bold());88- println!(" '{}' ran", fastest.result.command.cyan());89-90- for item in others {91- println!(92- "{} ± {} times faster than '{}'",93- format!("{:8.2}", item.relative_speed).bold().green(),94- format!("{:.2}", item.relative_speed_stddev).green(),95- &item.result.command.magenta()96- );97- }98- } else {99- eprintln!(100- "{}: The benchmark comparison could not be computed as some benchmark times are zero. \101- This could be caused by background interference during the initial calibration phase \102- of hyperfine, in combination with very fast commands (faster than a few milliseconds). \103- Try to re-run the benchmark on a quiet system. If it does not help, you command is \104- most likely too fast to be accurately benchmarked by hyperfine.",105- "Note".bold().red()106- );107- }108-}109-74 #[test]75 fn test_max() {76 let assert_float_eq = |a: f64, b: f64| {77 assert!((a - b).abs() < f64::EPSILON);53 unmodified linesmodified:src/main.rs+35 added-1 removed
26 unmodified lines27 pub mod warnings;28 29 use app::get_arg_matches;30 use benchmark::{mean_shell_spawning_time, run_benchmark};31+use benchmark_result::BenchmarkResult;32 use command::Command;33 use error::OptionsError;34 use export::{ExportManager, ExportType};34-use internal::write_benchmark_comparison;35 use options::{CmdFailureAction, HyperfineOptions, OutputStyleOption};36 use parameter_range::get_parameterized_commands;37 use tokenize::tokenize;38 use types::ParameterValue;4 unmodified lines43 eprintln!("{} {}", "Error:".red(), message);44 std::process::exit(1);45 }46 47+pub fn write_benchmark_comparison(results: &[BenchmarkResult]) {48+ if results.len() < 2 {49+ return;50+ }51+52+ if let Some(mut annotated_results) = internal::compute_relative_speed(results) {53+ annotated_results.sort_by(|l, r| internal::compare_mean_time(l.result, r.result));54+55+ let fastest = &annotated_results[0];56+ let others = &annotated_results[1..];57+58+ println!("{}", "Summary".bold());59+ println!(" '{}' ran", fastest.result.command.cyan());60+61+ for item in others {62+ println!(63+ "{} ± {} times faster than '{}'",64+ format!("{:8.2}", item.relative_speed).bold().green(),65+ format!("{:.2}", item.relative_speed_stddev).green(),66+ &item.result.command.magenta()67+ );68+ }69+ } else {70+ eprintln!(71+ "{}: The benchmark comparison could not be computed as some benchmark times are zero. \72+ This could be caused by background interference during the initial calibration phase \73+ of hyperfine, in combination with very fast commands (faster than a few milliseconds). \74+ Try to re-run the benchmark on a quiet system. If it does not help, you command is \75+ most likely too fast to be accurately benchmarked by hyperfine.",76+ "Note".bold().red()77+ );78+ }79+}80+81 /// Runs the benchmark for the given commands82 fn run(83 commands: &[Command<'_>],84 options: &HyperfineOptions,375 unmodified lines