Skip to content
Myr

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

2 files+36 added−38 removed

modified:src/internal.rs+1 added-37 removed
1use std::cmp::Ordering;2use std::iter::Iterator;34use colored::*;54use crate::benchmark_result::BenchmarkResult;5use crate::units::{Scalar, Second};67/// Threshold for warning about fast execution time
22 unmodified lines
30 pub relative_speed_stddev: Scalar,31 pub is_fastest: bool,32}3336fn compare_mean_time(l: &BenchmarkResult, r: &BenchmarkResult) -> Ordering {34pub fn compare_mean_time(l: &BenchmarkResult, r: &BenchmarkResult) -> Ordering {35 l.mean.partial_cmp(&r.mean).unwrap_or(Ordering::Equal)36}3738pub fn compute_relative_speed(
31 unmodified lines
70 .collect(),71 )72}7376pub fn write_benchmark_comparison(results: &[BenchmarkResult]) {77 if results.len() < 2 {78 return;79 }8081 if let Some(mut annotated_results) = compute_relative_speed(results) {82 annotated_results.sort_by(|l, r| compare_mean_time(l.result, r.result));8384 let fastest = &annotated_results[0];85 let others = &annotated_results[1..];8687 println!("{}", "Summary".bold());88 println!(" '{}' ran", fastest.result.command.cyan());8990 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}10974#[test]75fn test_max() {76 let assert_float_eq = |a: f64, b: f64| {77 assert!((a - b).abs() < f64::EPSILON);
53 unmodified lines
modified:src/main.rs+35 added-1 removed
26 unmodified lines
27pub mod warnings;2829use app::get_arg_matches;30use benchmark::{mean_shell_spawning_time, run_benchmark};31use benchmark_result::BenchmarkResult;32use command::Command;33use error::OptionsError;34use export::{ExportManager, ExportType};34use internal::write_benchmark_comparison;35use options::{CmdFailureAction, HyperfineOptions, OutputStyleOption};36use parameter_range::get_parameterized_commands;37use tokenize::tokenize;38use types::ParameterValue;
4 unmodified lines
43 eprintln!("{} {}", "Error:".red(), message);44 std::process::exit(1);45}4647pub fn write_benchmark_comparison(results: &[BenchmarkResult]) {48 if results.len() < 2 {49 return;50 }5152 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));5455 let fastest = &annotated_results[0];56 let others = &annotated_results[1..];5758 println!("{}", "Summary".bold());59 println!(" '{}' ran", fastest.result.command.cyan());6061 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}8081/// Runs the benchmark for the given commands82fn run(83 commands: &[Command<'_>],84 options: &HyperfineOptions,
375 unmodified lines