main.rs
This file
Path
src/main.rs
167 lines · 4.9 KiB · Rust
Last changed by
Initial working version with child proc HANDLE.Steve Pentlandbefore adoption9753eed
History of this fileTake it
Add new style option to disable coloring and progress bars (#24)Steve Pentlandbefore adoption2e24ff0
line 1why, one step back1extern crate atty;Modify clap settingssharkdpbefore adoption5cdf013
line 2why, one step back2#[macro_use]3extern crate clap;Update warnings, switch to colored cratesharkdpbefore adoptiond5c21ec
line 4why, one step back4extern crate colored;Add a progress barsharkdpbefore adoptiond4ebdd7
line 5why, one step back5extern crate indicatif;Use statistical cratesharkdpbefore adoption05e5899
line 6why, one step back6extern crate statistical;Initial changes to skip libc for cpu time on windowsSteve Pentlandbefore adoption1ddf729
line 7why, one step back7Initial working version with child proc HANDLE.Steve Pentlandbefore adoption9753eed
line 8why, one step back8#[cfg(not(windows))]Initial changes to skip libc for cpu time on windowsSteve Pentlandbefore adoption1ddf729
line 9why, one step back9extern crate libc;10Initial working version with child proc HANDLE.Steve Pentlandbefore adoption9753eed
line 11why, one step back11#[cfg(windows)]Initial windows timing supportSteve Pentlandbefore adoption42635fb
lines 12–13why, one step back12extern crate winapi;13Add unit testssharkdpbefore adoption241b89f
lines 14–17why, one step back14#[cfg(test)]15#[macro_use]16extern crate approx;17Add --min-runs, closes #2sharkdpbefore adoptiondab3f94
line 18why, one step back18use std::cmp;ErrorsHenri Menkebefore adoption219bb1e
lines 19–20why, one step back19use std::error::Error;20use std::io;21Add new style option to disable coloring and progress bars (#24)Steve Pentlandbefore adoption2e24ff0
line 22why, one step back22use atty::Stream;Update warnings, switch to colored cratesharkdpbefore adoptiond5c21ec
line 23why, one step back23use colored::*;Initial commitsharkdpbefore adoptiona658ab8
lines 24–2524use clap::{App, AppSettings, Arg};25Refactor code into separate modulessharkdpbefore adoption2ba3160
line 26why, one step back26mod hyperfine;Handling of errors and warningssharkdpbefore adoption7e41c2a
line 27why, one step back27Add new style option to disable coloring and progress bars (#24)Steve Pentlandbefore adoption2e24ff0
line 28why, one step back28use hyperfine::internal::{CmdFailureAction, HyperfineOptions, OutputStyleOption};Refactor code into separate modulessharkdpbefore adoption2ba3160
line 29why, one step back29use hyperfine::benchmark::{mean_shell_spawning_time, run_benchmark};Handling of errors and warningssharkdpbefore adoption7e41c2a
line 30why, one step back30ErrorsHenri Menkebefore adoption219bb1e
lines 31–32why, one step back31/// Print error message to stderr and terminate32pub fn error(message: &str) -> ! {Update warnings, switch to colored cratesharkdpbefore adoptiond5c21ec
line 33why, one step back33 eprintln!("{} {}", "Error:".red(), message);ErrorsHenri Menkebefore adoption219bb1e
lines 34–36why, one step back34 std::process::exit(1);35}36Correct for shell spawning time, closes #15sharkdpbefore adoption984cec7
lines 37–38why, one step back37/// Runs the benchmark for the given commands38fn run(commands: &Vec<&str>, options: &HyperfineOptions) -> io::Result<()> {Add new style option to disable coloring and progress bars (#24)Steve Pentlandbefore adoption2e24ff0
line 39why, one step back39 let shell_spawning_time = mean_shell_spawning_time(&options.output_style)?;Correct for shell spawning time, closes #15sharkdpbefore adoption984cec7
lines 40–41why, one step back4041 // Run the benchmarksOutput stylingsharkdpbefore adoption407c738
line 42why, one step back42 for (num, cmd) in commands.iter().enumerate() {Fix a few clippy warningssharkdpbefore adoption35a5139
line 43why, one step back43 run_benchmark(num, cmd, shell_spawning_time, options)?;Correct for shell spawning time, closes #15sharkdpbefore adoption984cec7
lines 44–46why, one step back44 }4546 Ok(())Refactoringsharkdpbefore adoption9ba7ada
lines 47–48why, one step back47}4849fn main() {Add --setup option, closes #8sharkdpbefore adoptiona4df90e
lines 50–52why, one step back50 // Process command line options51 let mut options = HyperfineOptions::default();52Add new style option to disable coloring and progress bars (#24)Steve Pentlandbefore adoption2e24ff0
lines 53–58why, one step back53 let clap_color_setting = if atty::is(Stream::Stdout) {54 AppSettings::ColoredHelp55 } else {56 AppSettings::ColorNever57 };5859 let matches = App::new("hyperfine")Modify clap settingssharkdpbefore adoption5cdf013
line 60why, one step back60 .version(crate_version!())Add new style option to disable coloring and progress bars (#24)Steve Pentlandbefore adoption2e24ff0
line 61why, one step back61 .setting(clap_color_setting)Modify clap settingssharkdpbefore adoption5cdf013
line 62why, one step back62 .setting(AppSettings::DeriveDisplayOrder)Clean up help textsharkdpbefore adoptionb6ca2d6
lines 63–64why, one step back63 .setting(AppSettings::UnifiedHelpMessage)64 .max_term_width(90)Update --help textsharkdpbefore adoptionf44f24c
line 65why, one step back65 .about("A command-line benchmarking tool.")Initial commitsharkdpbefore adoptiona658ab8
lines 66–6966 .arg(67 Arg::with_name("command")68 .help("Command to benchmark")69 .required(true)ErrorsHenri Menkebefore adoption219bb1e
lines 70–71why, one step back70 .multiple(true)71 .empty_values(false),72 )Add --warmup option, closes #1sharkdpbefore adoption68fdc2c
lines 73–78why, one step back73 .arg(74 Arg::with_name("warmup")75 .long("warmup")76 .short("w")77 .takes_value(true)78 .value_name("NUM")Add --setup option, closes #8sharkdpbefore adoptiona4df90e
lines 79–80why, one step back79 .help(80 "Perform NUM warmup runs before the actual benchmark. This can be used \Update --help textsharkdpbefore adoptionf44f24c
line 81why, one step back81 to fill (disk) caches for I/O-heavy programs.",Add --setup option, closes #8sharkdpbefore adoptiona4df90e
line 82why, one step back82 ),Add --warmup option, closes #1sharkdpbefore adoption68fdc2c
line 83why, one step back83 )Add --min-runs, closes #2sharkdpbefore adoptiondab3f94
lines 84–89why, one step back84 .arg(85 Arg::with_name("min-runs")86 .long("min-runs")87 .short("m")88 .takes_value(true)89 .value_name("NUM")Add --setup option, closes #8sharkdpbefore adoptiona4df90e
line 90why, one step back90 .help(&format!(Update --help textsharkdpbefore adoptionf44f24c
line 91why, one step back91 "Perform at least NUM runs for each command (default: {}).",Add --setup option, closes #8sharkdpbefore adoptiona4df90e
lines 92–93why, one step back92 options.min_runs93 )),Add --min-runs, closes #2sharkdpbefore adoptiondab3f94
line 94why, one step back94 )Clean up help textsharkdpbefore adoptionb6ca2d6
line 95why, one step back95 .arg(Rename --setup to --preparesharkdpbefore adoptiona656fbe
lines 96–98why, one step back96 Arg::with_name("prepare")97 .long("prepare")98 .short("p")Clean up help textsharkdpbefore adoptionb6ca2d6
lines 99–101why, one step back99 .takes_value(true)100 .value_name("CMD")101 .help(Rename --setup to --preparesharkdpbefore adoptiona656fbe
line 102why, one step back102 "Execute CMD before each timing run. This is useful for \Update --help textsharkdpbefore adoptionf44f24c
line 103why, one step back103 clearing disk caches, for example.",Clean up help textsharkdpbefore adoptionb6ca2d6
lines 104–105why, one step back104 ),105 )Rename --setup to --preparesharkdpbefore adoptiona656fbe
line 106why, one step back106 .arg(Add new style option to disable coloring and progress bars (#24)Steve Pentlandbefore adoption2e24ff0
lines 107–113why, one step back107 Arg::with_name("style")108 .long("style")109 .short("s")110 .takes_value(true)111 .value_name("TYPE")112 .possible_values(&["auto", "basic", "full"])113 .help(Updates for 0.4.0sharkdpbefore adoption89e6d37
lines 114–116why, one step back114 "Set output style type (default: auto). Set this to 'basic' to disable output \115 coloring and interactive elements. Set it to 'full' to enable all effects \116 even if no interactive terminal was detected.",Add new style option to disable coloring and progress bars (#24)Steve Pentlandbefore adoption2e24ff0
lines 117–119why, one step back117 ),118 )119 .arg(Rename --setup to --preparesharkdpbefore adoptiona656fbe
lines 120–122why, one step back120 Arg::with_name("ignore-failure")121 .long("ignore-failure")122 .short("i")Update --help textsharkdpbefore adoptionf44f24c
line 123why, one step back123 .help("Ignore non-zero exit codes."),Rename --setup to --preparesharkdpbefore adoptiona656fbe
line 124why, one step back124 )Update --help textsharkdpbefore adoptionf44f24c
lines 125–126why, one step back125 .help_message("Print this help message.")126 .version_message("Show version information.")Initial commitsharkdpbefore adoptiona658ab8
lines 127–128127 .get_matches();128Add --setup option, closes #8sharkdpbefore adoptiona4df90e
lines 129–130why, one step back129 let str_to_u64 = |n| u64::from_str_radix(n, 10).ok();130Warmup count as u64 onlysharkdpbefore adoption50b88b5
lines 131–134why, one step back131 options.warmup_count = matches132 .value_of("warmup")133 .and_then(&str_to_u64)134 .unwrap_or(0);Code style updatesharkdpbefore adoption197f9fb
line 135why, one step back135Add --min-runs, closes #2sharkdpbefore adoptiondab3f94
line 136why, one step back136 if let Some(min_runs) = matches.value_of("min-runs").and_then(&str_to_u64) {Use statistical cratesharkdpbefore adoption05e5899
lines 137–138why, one step back137 // we need at least two runs to compute a variance138 options.min_runs = cmp::max(2, min_runs);Add --min-runs, closes #2sharkdpbefore adoptiondab3f94
line 139why, one step back139 }Clean up help textsharkdpbefore adoptionb6ca2d6
line 140why, one step back140Rename --setup to --preparesharkdpbefore adoptiona656fbe
lines 141–142why, one step back141 options.preparation_command = matches.value_of("prepare").map(String::from);142Add new style option to disable coloring and progress bars (#24)Steve Pentlandbefore adoption2e24ff0
lines 143–151why, one step back143 options.output_style = match matches.value_of("style") {144 Some("full") => OutputStyleOption::Full,145 Some("basic") => OutputStyleOption::Basic,146 _ => if atty::is(Stream::Stdout) {147 OutputStyleOption::Full148 } else {149 OutputStyleOption::Basic150 },151 };Initial working version with child proc HANDLE.Steve Pentlandbefore adoption9753eed
line 152why, one step back152No hybrid between basic and fullsharkdpbefore adoptioneb92bd4
lines 153–154why, one step back153 if options.output_style == OutputStyleOption::Basic {154 colored::control::set_override(false);Exclude entire cputime file, force basic outputSteve Pentlandbefore adoptionff798ad
lines 155–156why, one step back155 }156Use enum instead of boolsharkdpbefore adoptiond42994b
lines 157–159why, one step back157 if matches.is_present("ignore-failure") {158 options.failure_action = CmdFailureAction::Ignore;159 }Add --min-runs, closes #2sharkdpbefore adoptiondab3f94
line 160why, one step back160Correct for shell spawning time, closes #15sharkdpbefore adoption984cec7
lines 161–162why, one step back161 let commands = matches.values_of("command").unwrap().collect();162 let res = run(&commands, &options);Handling of errors and warningssharkdpbefore adoption7e41c2a
line 163why, one step back163Fix a few clippy warningssharkdpbefore adoption35a5139
lines 164–165why, one step back164 if let Err(e) = res {165 error(e.description());Initial commitsharkdpbefore adoptiona658ab8
lines 166–167166 }167}