Rename --setup to --prepare
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by sharkdp · committed by sharkdp · parent d5e02ff · Browse files · 4 files·+39 added−30 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+39 added−30 removed
- other:+39 added−30 removed
Provenance
- Commit
a656fbe- Tree
0f15d12- Author
sharkdp <davidpeter@web.de>- Committer
sharkdp <davidpeter@web.de>- Parent
d5e02ff
4 files changed+39 added−30 removed
modified:src/hyperfine/benchmark.rs+6 added-6 removed
131 unmodified lines132 133 // Set up progress bar (and spinner for initial measurement)134 let bar = get_progress_bar(options.min_runs, "Initial time measurement");135 136- // Run setup / cleanup command137- let run_setup_command = || {138- if let Some(ref setup_command) = options.setup_command {139- let _ = time_shell_command(setup_command, options.ignore_failure, None);136+ // Run init / cleanup command137+ let run_preparation_command = || {138+ if let Some(ref preparation_command) = options.preparation_command {139+ let _ = time_shell_command(preparation_command, options.ignore_failure, None);140 }141 };142- run_setup_command();142+ run_preparation_command();143 144 // Initial timing run145 let res = time_shell_command(cmd, options.ignore_failure, Some(shell_spawning_time))?;146 17 unmodified lines164 bar.set_length(count_remaining);165 166 // Gather statistics167 for _ in 0..count_remaining {168- run_setup_command();168+ run_preparation_command();169 170 let msg = {171 let mean = format_duration(mean(&execution_times), Unit::Auto);172 format!("Current estimate: {}", Green.paint(mean))65 unmodified linesmodified:src/hyperfine/internal.rs+3 added-3 removed
20 unmodified lines21 22 /// Whether or not to ignore non-zero exit codes23 pub ignore_failure: bool,24 25- /// Command to run before each benchmark run26- pub setup_command: Option<String>,25+ /// Command to run before each timing run26+ pub preparation_command: Option<String>,27 }28 29 impl Default for HyperfineOptions {30 fn default() -> HyperfineOptions {1 unmodified line32 warmup_count: 0,33 min_runs: 10,34 min_time_sec: 3.0,35 ignore_failure: false,36- setup_command: None,36+ preparation_command: None,37 }38 }39 }40 48 unmodified linesmodified:src/main.rs+13 added-13 removed
51 unmodified lines52 .multiple(true)53 .empty_values(false),54 )55 .arg(56- Arg::with_name("ignore-failure")57- .long("ignore-failure")58- .short("i")59- .help("Ignore non-zero exit codes"),60- )61- .arg(56 Arg::with_name("warmup")57 .long("warmup")58 .short("w")59 .takes_value(true)14 unmodified lines74 options.min_runs75 )),76 )77 .arg(84- Arg::with_name("setup")85- .long("setup")86- .short("S")78+ Arg::with_name("prepare")79+ .long("prepare")80+ .short("p")81 .takes_value(true)82 .value_name("CMD")83 .help(90- "Execute CMD before each benchmark run. This is useful for \84+ "Execute CMD before each timing run. This is useful for \85 clearing disk caches, for example",86 ),87 )88+ .arg(89+ Arg::with_name("ignore-failure")90+ .long("ignore-failure")91+ .short("i")92+ .help("Ignore non-zero exit codes"),93+ )94 .get_matches();95 96- options.ignore_failure = matches.is_present("ignore-failure");97-96 let str_to_u64 = |n| u64::from_str_radix(n, 10).ok();97 98 options.warmup_count = matches99 .value_of("warmup")4 unmodified lines104 // we need at least two runs to compute a variance105 options.min_runs = cmp::max(2, min_runs);106 }107 110- options.setup_command = matches.value_of("setup").map(String::from);108+ options.preparation_command = matches.value_of("prepare").map(String::from);109 110+ options.ignore_failure = matches.is_present("ignore-failure");111+112 let commands = matches.values_of("command").unwrap().collect();113 let res = run(&commands, &options);114 115 match res {4 unmodified linesmodified:README.md+17 added-8 removed
1234556789106 unmodified lines1718192020212223242526252728293031323334353236373834394041424344394546474849504351525345545556575817 unmodified lines# hyperfine
A command-line benchmarking tool (*inspired by [bench](https://github.com/Gabriel439/bench)*).
**Demo**: Benchmarking [`fd`](https://github.com/sharkdp/fd) and [`find`](https://www.gnu.org/software/findutils/):**Demo**: Benchmarking [`fd`](https://github.com/sharkdp/fd) and[`find`](https://www.gnu.org/software/findutils/):

## Features6 unmodified lines## Usage
### Basic benchmark
To run a benchmark, you can simply call `hyperfine <command>...` where the argument(s) can be any shell command. For example:To run a benchmark, you can simply call `hyperfine <command>...`. The argument(s) can be anyshell command. For example:``` bash> hyperfine 'sleep 0.3'```
Hyperfine will automatically determine the number of runs to perform for each command. By default, it will perform *at least* 10 benchmarking runs. To change this, you can use the `-m`/`--min-runs` option:Hyperfine will automatically determine the number of runs to perform for each command. By default,it will perform *at least* 10 benchmarking runs. To change this, you can use the `-m`/`--min-runs`option:``` bash> hyperfine --min-runs 5 'sleep 0.2' 'sleep 3.2'```
### I/O-heavy programs
If the program execution time is limited by disk I/O, the benchmarking results can be heavily influence by disk caches and whether they are cold or warm.If the program execution time is limited by disk I/O, the benchmarking results can be heavilyinfluence by disk caches and whether they are cold or warm.
If you want to run the benchmark on a warm cache, you can use the `-w`/`--warmup` option to perform a certain amount of program executions before the actual benchmark:If you want to run the benchmark on a warm cache, you can use the `-w`/`--warmup` option to performa certain number of program executions before the actual benchmark:``` bash> hyperfine --warmup 3 'grep -R TODO *'```
Conversely, if you want to run the benchmark for a cold cache, you can use the `-S`/`--setup` option to run a special command before *each* benchmarking run. For example, to clear disk caches on Linux, you can runConversely, if you want to run the benchmark for a cold cache, you can use the `-p`/`--prepare`option to run a special command before *each* timing run. For example, to clear harddisk cacheson Linux, you can run``` bashsync; echo 3 | sudo tee /proc/sys/vm/drop_caches```To use this with Hyperfine, call `sudo echo` to temporarily gain sudo permissions and then call:To use this specific command with Hyperfine, call `sudo echo` to temporarily gain sudo permissionsand then call:``` bashhyperfine -S 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' 'grep -R TODO *'hyperfine --prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' 'grep -R TODO *'```
## Installation
17 unmodified lines