mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-28 19:00:58 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ab998428c |
No files matched your search
@@ -18,7 +18,7 @@ jobs:
|
|||||||
name: Extract crate metadata
|
name: Extract crate metadata
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
- name: Extract crate information
|
- name: Extract crate information
|
||||||
id: crate_metadata
|
id: crate_metadata
|
||||||
run: |
|
run: |
|
||||||
@@ -49,7 +49,7 @@ jobs:
|
|||||||
- uses: dtolnay/rust-toolchain@stable
|
- uses: dtolnay/rust-toolchain@stable
|
||||||
with:
|
with:
|
||||||
components: rustfmt
|
components: rustfmt
|
||||||
- uses: actions/checkout@v5
|
- uses: actions/checkout@v4
|
||||||
- run: cargo fmt -- --check
|
- run: cargo fmt -- --check
|
||||||
|
|
||||||
min_version:
|
min_version:
|
||||||
@@ -58,7 +58,7 @@ jobs:
|
|||||||
needs: crate_metadata
|
needs: crate_metadata
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout source code
|
- name: Checkout source code
|
||||||
uses: actions/checkout@v5
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install rust toolchain (v${{ needs.crate_metadata.outputs.msrv }})
|
- name: Install rust toolchain (v${{ needs.crate_metadata.outputs.msrv }})
|
||||||
uses: dtolnay/rust-toolchain@master
|
uses: dtolnay/rust-toolchain@master
|
||||||
@@ -79,7 +79,6 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
job:
|
job:
|
||||||
- { target: aarch64-unknown-linux-gnu , os: ubuntu-24.04, use-cross: true }
|
- { target: aarch64-unknown-linux-gnu , os: ubuntu-24.04, use-cross: true }
|
||||||
- { target: aarch64-unknown-linux-musl , os: ubuntu-24.04, use-cross: true }
|
|
||||||
- { target: arm-unknown-linux-gnueabihf , os: ubuntu-24.04, use-cross: true }
|
- { target: arm-unknown-linux-gnueabihf , os: ubuntu-24.04, use-cross: true }
|
||||||
- { target: arm-unknown-linux-musleabihf, os: ubuntu-24.04, use-cross: true }
|
- { target: arm-unknown-linux-musleabihf, os: ubuntu-24.04, use-cross: true }
|
||||||
- { target: i686-pc-windows-msvc , os: windows-2022 }
|
- { target: i686-pc-windows-msvc , os: windows-2022 }
|
||||||
@@ -95,7 +94,7 @@ jobs:
|
|||||||
BUILD_CMD: cargo
|
BUILD_CMD: cargo
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout source code
|
- name: Checkout source code
|
||||||
uses: actions/checkout@v5
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install prerequisites
|
- name: Install prerequisites
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|||||||
+1
-18
@@ -1,20 +1,3 @@
|
|||||||
# v1.20.0
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- Add `--reference-name` option to give a meaningful name to the reference command, see #808 (@niklasdewally)
|
|
||||||
- The `--ignore-failure` option now supports a comma-separated list of exit codes to ignore (e.g., `--ignore-failure=1,2`), see #836 (@sharkdp)
|
|
||||||
- Python scripts: Add `--time-unit` option to `advanced_statistics.py` (@sharkdp)
|
|
||||||
- Python scripts: Add new `plot_benchmarks.py` script for plotting collections of benchmarks, see #806 (@marxin)
|
|
||||||
|
|
||||||
## Bugfixes
|
|
||||||
|
|
||||||
- Fix bug where naming individual commands with parameter scan was not working correctly, see #794 (@teofr)
|
|
||||||
|
|
||||||
## Other
|
|
||||||
|
|
||||||
- Restrict `cat` tests to Unix environments, see #776 and #777 (@ritvikos)
|
|
||||||
|
|
||||||
# v1.19.0
|
# v1.19.0
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
@@ -247,7 +230,7 @@ Package authors: note that Hyperfine now comes with a set of shell completion fi
|
|||||||
necessarily required numeric arguments.
|
necessarily required numeric arguments.
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
hyperfine --parameter-list compiler "g++,clang++" \
|
hyperfine --parameter-list compiler "gcc,clang" \
|
||||||
"{compiler} -O2 main.cpp"
|
"{compiler} -O2 main.cpp"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -13,5 +13,5 @@ authors:
|
|||||||
repository-code: 'https://github.com/sharkdp/hyperfine'
|
repository-code: 'https://github.com/sharkdp/hyperfine'
|
||||||
abstract: A command-line benchmarking tool.
|
abstract: A command-line benchmarking tool.
|
||||||
license: MIT
|
license: MIT
|
||||||
version: 1.20.0
|
version: 1.16.1
|
||||||
date-released: '2025-11-18'
|
date-released: '2023-03-21'
|
||||||
Generated
+481
-446
File diff suppressed because it is too large.
Load diff
+15
-16
@@ -7,26 +7,25 @@ license = "MIT OR Apache-2.0"
|
|||||||
name = "hyperfine"
|
name = "hyperfine"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
repository = "https://github.com/sharkdp/hyperfine"
|
repository = "https://github.com/sharkdp/hyperfine"
|
||||||
version = "1.20.0"
|
version = "1.19.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
rust-version = "1.97.0"
|
rust-version = "1.88.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
# Use the nightly feature windows_process_extensions_main_thread_handle
|
# Use the nightly feature windows_process_extensions_main_thread_handle
|
||||||
windows_process_extensions_main_thread_handle = []
|
windows_process_extensions_main_thread_handle = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
colored = "3.1"
|
colored = "2.1"
|
||||||
# Newer versions regress ETA estimates: https://github.com/console-rs/indicatif/issues/580
|
|
||||||
indicatif = "=0.17.4"
|
indicatif = "=0.17.4"
|
||||||
statistical = "1.0"
|
statistical = "1.0"
|
||||||
csv = "1.4"
|
csv = "1.3"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
rust_decimal = "1.43"
|
rust_decimal = "1.36"
|
||||||
rand = "0.10"
|
rand = "0.8"
|
||||||
shell-words = "1.1"
|
shell-words = "1.0"
|
||||||
thiserror = "2.0"
|
thiserror = "2.0"
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
|
|
||||||
@@ -34,7 +33,7 @@ anyhow = "1.0"
|
|||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
windows-sys = { version = "0.61", features = [
|
windows-sys = { version = "0.59", features = [
|
||||||
"Win32_Foundation",
|
"Win32_Foundation",
|
||||||
"Win32_Security",
|
"Win32_Security",
|
||||||
"Win32_System_JobObjects",
|
"Win32_System_JobObjects",
|
||||||
@@ -43,10 +42,10 @@ windows-sys = { version = "0.61", features = [
|
|||||||
] }
|
] }
|
||||||
|
|
||||||
[target.'cfg(all(windows, not(windows_process_extensions_main_thread_handle)))'.dependencies]
|
[target.'cfg(all(windows, not(windows_process_extensions_main_thread_handle)))'.dependencies]
|
||||||
once_cell = "1.21"
|
once_cell = "1.19"
|
||||||
|
|
||||||
[target.'cfg(target_os="linux")'.dependencies]
|
[target.'cfg(target_os="linux")'.dependencies]
|
||||||
nix = { version = "0.31", features = ["zerocopy"] }
|
nix = { version = "0.29", features = ["zerocopy"] }
|
||||||
|
|
||||||
[dependencies.clap]
|
[dependencies.clap]
|
||||||
version = "4"
|
version = "4"
|
||||||
@@ -63,18 +62,18 @@ features = [
|
|||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
approx = "0.5"
|
approx = "0.5"
|
||||||
assert_cmd = "2.2"
|
assert_cmd = "2.0"
|
||||||
insta = { version = "1.48", features = ["yaml"] }
|
insta = { version = "1.41.1", features = ["yaml"] }
|
||||||
predicates = "3.1"
|
predicates = "3.1"
|
||||||
tempfile = "3.27"
|
tempfile = "3.14"
|
||||||
|
|
||||||
[profile.dev.package]
|
[profile.dev.package]
|
||||||
insta.opt-level = 3
|
insta.opt-level = 3
|
||||||
similar.opt-level = 3
|
similar.opt-level = 3
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
clap = "4.6"
|
clap = "4.5.47"
|
||||||
clap_complete = "4.6"
|
clap_complete = "4.2.1"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
|
|||||||
@@ -10,6 +10,29 @@ A command-line benchmarking tool.
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
### Sponsors
|
||||||
|
|
||||||
|
A special *thank you* goes to our biggest <a href="doc/sponsors.md">sponsors</a>:<br>
|
||||||
|
|
||||||
|
<a href="https://www.warp.dev/hyperfine">
|
||||||
|
<img src="doc/sponsors/warp-logo.png" width="200" alt="Warp">
|
||||||
|
<br>
|
||||||
|
<strong>Warp, the intelligent terminal</strong>
|
||||||
|
<br>
|
||||||
|
<sub>Available on MacOS, Linux, Windows</sub>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<a href="https://tuple.app/hyperfine">
|
||||||
|
<img src="doc/sponsors/tuple-logo.png" width="200" alt="Tuple">
|
||||||
|
<br>
|
||||||
|
<strong>Tuple, the premier screen sharing app for developers</strong>
|
||||||
|
<br>
|
||||||
|
<sub>Available for MacOS & Windows</sub>
|
||||||
|
</a>
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
* Statistical analysis across multiple runs.
|
* Statistical analysis across multiple runs.
|
||||||
@@ -84,7 +107,7 @@ This runs `sleep 0.3`, `sleep 0.5` and `sleep 0.7`.
|
|||||||
For non-numeric parameters, you can also supply a list of values with the `-L`/`--parameter-list`
|
For non-numeric parameters, you can also supply a list of values with the `-L`/`--parameter-list`
|
||||||
option:
|
option:
|
||||||
```
|
```
|
||||||
hyperfine -L compiler g++,clang++ '{compiler} -O2 main.cpp'
|
hyperfine -L compiler gcc,clang '{compiler} -O2 main.cpp'
|
||||||
```
|
```
|
||||||
|
|
||||||
### Intermediate shell
|
### Intermediate shell
|
||||||
@@ -108,7 +131,7 @@ hyperfine -N 'grep TODO /home/user'
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Shell functions
|
### Shell functions and aliases
|
||||||
|
|
||||||
If you are using bash, you can export shell functions to directly benchmark them with hyperfine:
|
If you are using bash, you can export shell functions to directly benchmark them with hyperfine:
|
||||||
|
|
||||||
@@ -118,10 +141,13 @@ export -f my_function
|
|||||||
hyperfine --shell=bash my_function
|
hyperfine --shell=bash my_function
|
||||||
```
|
```
|
||||||
|
|
||||||
Otherwise, inline the function into the benchmarked command:
|
Otherwise, inline them into or source them from the benchmarked program:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
hyperfine 'my_function() { sleep 1; }; my_function'
|
hyperfine 'my_function() { sleep 1; }; my_function'
|
||||||
|
|
||||||
|
echo 'alias my_alias="sleep 1"' > /tmp/my_alias.sh
|
||||||
|
hyperfine '. /tmp/my_alias.sh; my_alias'
|
||||||
```
|
```
|
||||||
|
|
||||||
### Exporting results
|
### Exporting results
|
||||||
@@ -171,8 +197,8 @@ apt install hyperfine
|
|||||||
|
|
||||||
Alternatively, for the latest version, you can download the appropriate `.deb` package from the [Release page](https://github.com/sharkdp/hyperfine/releases) and install it via `dpkg`:
|
Alternatively, for the latest version, you can download the appropriate `.deb` package from the [Release page](https://github.com/sharkdp/hyperfine/releases) and install it via `dpkg`:
|
||||||
```
|
```
|
||||||
wget https://github.com/sharkdp/hyperfine/releases/download/v1.20.0/hyperfine_1.20.0_amd64.deb
|
wget https://github.com/sharkdp/hyperfine/releases/download/v1.19.0/hyperfine_1.19.0_amd64.deb
|
||||||
sudo dpkg -i hyperfine_1.20.0_amd64.deb
|
sudo dpkg -i hyperfine_1.19.0_amd64.deb
|
||||||
```
|
```
|
||||||
|
|
||||||
### On Fedora
|
### On Fedora
|
||||||
@@ -199,7 +225,7 @@ pacman -S hyperfine
|
|||||||
|
|
||||||
### On Debian Linux
|
### On Debian Linux
|
||||||
|
|
||||||
On Debian Linux, hyperfine can be installed [from the official repositories](https://packages.debian.org/hyperfine):
|
On Debian Linux, hyperfine can be installed [from the testing repositories](https://packages.debian.org/testing/main/hyperfine):
|
||||||
```
|
```
|
||||||
apt install hyperfine
|
apt install hyperfine
|
||||||
```
|
```
|
||||||
@@ -302,7 +328,7 @@ Hyperfine can be installed from source via [cargo](https://doc.rust-lang.org/car
|
|||||||
cargo install --locked hyperfine
|
cargo install --locked hyperfine
|
||||||
```
|
```
|
||||||
|
|
||||||
Make sure that you use Rust 1.97 or newer.
|
Make sure that you use Rust 1.76 or newer.
|
||||||
|
|
||||||
### From binaries (Linux, macOS, Windows)
|
### From binaries (Linux, macOS, Windows)
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -131,7 +131,7 @@ Execute \fICMD\fP after the completion of all benchmarking runs for each individ
|
|||||||
command to be benchmarked. This is useful if the commands to be benchmarked
|
command to be benchmarked. This is useful if the commands to be benchmarked
|
||||||
produce artifacts that need to be cleaned up. It only runs once a series of
|
produce artifacts that need to be cleaned up. It only runs once a series of
|
||||||
benchmark runs, as opposed to \fB\-\-conclude\fR option which runs after
|
benchmark runs, as opposed to \fB\-\-conclude\fR option which runs after
|
||||||
every run.
|
ever run.
|
||||||
.HP
|
.HP
|
||||||
\fB\-P\fR, \fB\-\-parameter\-scan\fR \fIVAR\fP \fIMIN\fP \fIMAX\fP
|
\fB\-P\fR, \fB\-\-parameter\-scan\fR \fIVAR\fP \fIMIN\fP \fIMAX\fP
|
||||||
.IP
|
.IP
|
||||||
@@ -184,11 +184,11 @@ Replaces the string '{\fIVAR\fP}' in each command by the current parameter value
|
|||||||
.RS
|
.RS
|
||||||
Example:
|
Example:
|
||||||
.RS
|
.RS
|
||||||
\fBhyperfine\fR \fB\-L\fR compiler g++,clang++ '{compiler} \-O2 main.cpp'
|
\fBhyperfine\fR \fB\-L\fR compiler gcc,clang '{compiler} \-O2 main.cpp'
|
||||||
.RE
|
.RE
|
||||||
.RE
|
.RE
|
||||||
.IP
|
.IP
|
||||||
This performs benchmarks for 'g++ \-O2 main.cpp' and 'clang++ \-O2 main.cpp'.
|
This performs benchmarks for 'gcc \-O2 main.cpp' and 'clang \-O2 main.cpp'.
|
||||||
.IP
|
.IP
|
||||||
The option can be specified multiple times to run benchmarks for all
|
The option can be specified multiple times to run benchmarks for all
|
||||||
possible parameter combinations.
|
possible parameter combinations.
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
## Sponsors
|
||||||
|
|
||||||
|
`hyperfine` development is sponsored by many individuals and companies. Thank you very much!
|
||||||
|
|
||||||
|
Please note, that being sponsored does not affect the individuality of the `hyperfine`
|
||||||
|
project or affect the maintainers' actions in any way.
|
||||||
|
We remain impartial and continue to assess pull requests solely on merit - the
|
||||||
|
features added, bugs solved, and effect on the overall complexity of the code.
|
||||||
|
No issue will have a different priority based on sponsorship status of the
|
||||||
|
reporter.
|
||||||
|
|
||||||
|
Contributions from anybody are most welcomed.
|
||||||
|
|
||||||
|
If you want to see our biggest sponsors, check the top of [`README.md`](../README.md#sponsors).
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 130 KiB |
+11
-19
@@ -5,7 +5,6 @@ pub mod scheduler;
|
|||||||
pub mod timing_result;
|
pub mod timing_result;
|
||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::io::{self, Write};
|
|
||||||
|
|
||||||
use crate::benchmark::executor::BenchmarkIteration;
|
use crate::benchmark::executor::BenchmarkIteration;
|
||||||
use crate::command::Command;
|
use crate::command::Command;
|
||||||
@@ -13,7 +12,6 @@ use crate::options::{
|
|||||||
CmdFailureAction, CommandOutputPolicy, ExecutorKind, Options, OutputStyleOption,
|
CmdFailureAction, CommandOutputPolicy, ExecutorKind, Options, OutputStyleOption,
|
||||||
};
|
};
|
||||||
use crate::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD};
|
use crate::outlier_detection::{modified_zscores, OUTLIER_THRESHOLD};
|
||||||
use crate::output::console_writeln;
|
|
||||||
use crate::output::format::{format_duration, format_duration_unit};
|
use crate::output::format::{format_duration, format_duration_unit};
|
||||||
use crate::output::progress_bar::get_progress_bar;
|
use crate::output::progress_bar::get_progress_bar;
|
||||||
use crate::output::warnings::{OutlierWarningOptions, Warnings};
|
use crate::output::warnings::{OutlierWarningOptions, Warnings};
|
||||||
@@ -142,13 +140,12 @@ impl<'a> Benchmark<'a> {
|
|||||||
/// Run the benchmark for a single command
|
/// Run the benchmark for a single command
|
||||||
pub fn run(&self) -> Result<BenchmarkResult> {
|
pub fn run(&self) -> Result<BenchmarkResult> {
|
||||||
if self.options.output_style != OutputStyleOption::Disabled {
|
if self.options.output_style != OutputStyleOption::Disabled {
|
||||||
console_writeln!(
|
println!(
|
||||||
io::stdout(),
|
|
||||||
"{}{}: {}",
|
"{}{}: {}",
|
||||||
"Benchmark ".bold(),
|
"Benchmark ".bold(),
|
||||||
(self.number + 1).to_string().bold(),
|
(self.number + 1).to_string().bold(),
|
||||||
self.command.get_name_with_unused_parameters(),
|
self.command.get_name_with_unused_parameters(),
|
||||||
)?;
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut times_real: Vec<Second> = vec![];
|
let mut times_real: Vec<Second> = vec![];
|
||||||
@@ -361,22 +358,19 @@ impl<'a> Benchmark<'a> {
|
|||||||
let system_str = format_duration(system_mean, Some(time_unit));
|
let system_str = format_duration(system_mean, Some(time_unit));
|
||||||
|
|
||||||
if self.options.output_style != OutputStyleOption::Disabled {
|
if self.options.output_style != OutputStyleOption::Disabled {
|
||||||
let mut stdout = io::stdout().lock();
|
|
||||||
if times_real.len() == 1 {
|
if times_real.len() == 1 {
|
||||||
console_writeln!(
|
println!(
|
||||||
stdout,
|
|
||||||
" Time ({} ≡): {:>8} {:>8} [User: {}, System: {}]",
|
" Time ({} ≡): {:>8} {:>8} [User: {}, System: {}]",
|
||||||
"abs".green().bold(),
|
"abs".green().bold(),
|
||||||
mean_str.green().bold(),
|
mean_str.green().bold(),
|
||||||
" ", // alignment
|
" ", // alignment
|
||||||
user_str.blue(),
|
user_str.blue(),
|
||||||
system_str.blue()
|
system_str.blue()
|
||||||
)?;
|
);
|
||||||
} else {
|
} else {
|
||||||
let stddev_str = format_duration(t_stddev.unwrap(), Some(time_unit));
|
let stddev_str = format_duration(t_stddev.unwrap(), Some(time_unit));
|
||||||
|
|
||||||
console_writeln!(
|
println!(
|
||||||
stdout,
|
|
||||||
" Time ({} ± {}): {:>8} ± {:>8} [User: {}, System: {}]",
|
" Time ({} ± {}): {:>8} ± {:>8} [User: {}, System: {}]",
|
||||||
"mean".green().bold(),
|
"mean".green().bold(),
|
||||||
"σ".green(),
|
"σ".green(),
|
||||||
@@ -384,17 +378,16 @@ impl<'a> Benchmark<'a> {
|
|||||||
stddev_str.green(),
|
stddev_str.green(),
|
||||||
user_str.blue(),
|
user_str.blue(),
|
||||||
system_str.blue()
|
system_str.blue()
|
||||||
)?;
|
);
|
||||||
|
|
||||||
console_writeln!(
|
println!(
|
||||||
stdout,
|
|
||||||
" Range ({} … {}): {:>8} … {:>8} {}",
|
" Range ({} … {}): {:>8} … {:>8} {}",
|
||||||
"min".cyan(),
|
"min".cyan(),
|
||||||
"max".purple(),
|
"max".purple(),
|
||||||
min_str.cyan(),
|
min_str.cyan(),
|
||||||
max_str.purple(),
|
max_str.purple(),
|
||||||
num_str.dimmed()
|
num_str.dimmed()
|
||||||
)?;
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -437,16 +430,15 @@ impl<'a> Benchmark<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !warnings.is_empty() {
|
if !warnings.is_empty() {
|
||||||
let mut stderr = io::stderr().lock();
|
eprintln!(" ");
|
||||||
console_writeln!(stderr, " ")?;
|
|
||||||
|
|
||||||
for warning in &warnings {
|
for warning in &warnings {
|
||||||
console_writeln!(stderr, " {}: {}", "Warning".yellow(), warning)?;
|
eprintln!(" {}: {}", "Warning".yellow(), warning);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.options.output_style != OutputStyleOption::Disabled {
|
if self.options.output_style != OutputStyleOption::Disabled {
|
||||||
console_writeln!(io::stdout(), " ")?;
|
println!(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
self.run_cleanup_command(self.command.get_parameters().iter().cloned(), output_policy)?;
|
self.run_cleanup_command(self.command.get_parameters().iter().cloned(), output_policy)?;
|
||||||
|
|||||||
+15
-24
@@ -3,12 +3,10 @@ use super::executor::{Executor, MockExecutor, RawExecutor, ShellExecutor};
|
|||||||
use super::{relative_speed, Benchmark};
|
use super::{relative_speed, Benchmark};
|
||||||
use colored::*;
|
use colored::*;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::io::{self, Write};
|
|
||||||
|
|
||||||
use crate::command::{Command, Commands};
|
use crate::command::{Command, Commands};
|
||||||
use crate::export::ExportManager;
|
use crate::export::ExportManager;
|
||||||
use crate::options::{ExecutorKind, Options, OutputStyleOption, SortOrder};
|
use crate::options::{ExecutorKind, Options, OutputStyleOption, SortOrder};
|
||||||
use crate::output::console_writeln;
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
@@ -60,13 +58,13 @@ impl<'a> Scheduler<'a> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_relative_speed_comparison(&self) -> Result<()> {
|
pub fn print_relative_speed_comparison(&self) {
|
||||||
if self.options.output_style == OutputStyleOption::Disabled {
|
if self.options.output_style == OutputStyleOption::Disabled {
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.results.len() < 2 {
|
if self.results.len() < 2 {
|
||||||
return Ok(());
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let reference = self
|
let reference = self
|
||||||
@@ -81,19 +79,17 @@ impl<'a> Scheduler<'a> {
|
|||||||
reference,
|
reference,
|
||||||
self.options.sort_order_speed_comparison,
|
self.options.sort_order_speed_comparison,
|
||||||
) {
|
) {
|
||||||
let mut stdout = io::stdout().lock();
|
|
||||||
match self.options.sort_order_speed_comparison {
|
match self.options.sort_order_speed_comparison {
|
||||||
SortOrder::MeanTime => {
|
SortOrder::MeanTime => {
|
||||||
console_writeln!(stdout, "{}", "Summary".bold())?;
|
println!("{}", "Summary".bold());
|
||||||
|
|
||||||
let reference = annotated_results.iter().find(|r| r.is_reference).unwrap();
|
let reference = annotated_results.iter().find(|r| r.is_reference).unwrap();
|
||||||
let others = annotated_results.iter().filter(|r| !r.is_reference);
|
let others = annotated_results.iter().filter(|r| !r.is_reference);
|
||||||
|
|
||||||
console_writeln!(
|
println!(
|
||||||
stdout,
|
|
||||||
" {} ran",
|
" {} ran",
|
||||||
reference.result.command_with_unused_parameters.cyan()
|
reference.result.command_with_unused_parameters.cyan()
|
||||||
)?;
|
);
|
||||||
|
|
||||||
for item in others {
|
for item in others {
|
||||||
let stddev = if let Some(stddev) = item.relative_speed_stddev {
|
let stddev = if let Some(stddev) = item.relative_speed_stddev {
|
||||||
@@ -118,20 +114,18 @@ impl<'a> Scheduler<'a> {
|
|||||||
stddev
|
stddev
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
console_writeln!(
|
println!(
|
||||||
stdout,
|
|
||||||
"{} {}",
|
"{} {}",
|
||||||
comparator,
|
comparator,
|
||||||
item.result.command_with_unused_parameters.magenta()
|
&item.result.command_with_unused_parameters.magenta()
|
||||||
)?;
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SortOrder::Command => {
|
SortOrder::Command => {
|
||||||
console_writeln!(stdout, "{}", "Relative speed comparison".bold())?;
|
println!("{}", "Relative speed comparison".bold());
|
||||||
|
|
||||||
for item in annotated_results {
|
for item in annotated_results {
|
||||||
console_writeln!(
|
println!(
|
||||||
stdout,
|
|
||||||
" {}{} {}",
|
" {}{} {}",
|
||||||
format!("{:10.2}", item.relative_speed).bold().green(),
|
format!("{:10.2}", item.relative_speed).bold().green(),
|
||||||
if item.is_reference {
|
if item.is_reference {
|
||||||
@@ -141,14 +135,13 @@ impl<'a> Scheduler<'a> {
|
|||||||
} else {
|
} else {
|
||||||
" ".into()
|
" ".into()
|
||||||
},
|
},
|
||||||
item.result.command_with_unused_parameters,
|
&item.result.command_with_unused_parameters,
|
||||||
)?;
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console_writeln!(
|
eprintln!(
|
||||||
io::stderr(),
|
|
||||||
"{}: The benchmark comparison could not be computed as some benchmark times are zero. \
|
"{}: The benchmark comparison could not be computed as some benchmark times are zero. \
|
||||||
This could be caused by background interference during the initial calibration phase \
|
This could be caused by background interference during the initial calibration phase \
|
||||||
of hyperfine, in combination with very fast commands (faster than a few milliseconds). \
|
of hyperfine, in combination with very fast commands (faster than a few milliseconds). \
|
||||||
@@ -156,10 +149,8 @@ impl<'a> Scheduler<'a> {
|
|||||||
--shell=none/-N option. If it does not help either, you command is most likely too fast \
|
--shell=none/-N option. If it does not help either, you command is most likely too fast \
|
||||||
to be accurately benchmarked by hyperfine.",
|
to be accurately benchmarked by hyperfine.",
|
||||||
"Note".bold().red()
|
"Note".bold().red()
|
||||||
)?;
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn final_export(&self) -> Result<()> {
|
pub fn final_export(&self) -> Result<()> {
|
||||||
|
|||||||
+2
-2
@@ -194,8 +194,8 @@ fn build_command() -> Command {
|
|||||||
.help(
|
.help(
|
||||||
"Perform benchmark runs for each value in the comma-separated list VALUES. \
|
"Perform benchmark runs for each value in the comma-separated list VALUES. \
|
||||||
Replaces the string '{VAR}' in each command by the current parameter value\
|
Replaces the string '{VAR}' in each command by the current parameter value\
|
||||||
.\n\nExample: hyperfine -L compiler g++,clang++ '{compiler} -O2 main.cpp'\n\n\
|
.\n\nExample: hyperfine -L compiler gcc,clang '{compiler} -O2 main.cpp'\n\n\
|
||||||
This performs benchmarks for 'g++ -O2 main.cpp' and 'clang++ -O2 main.cpp'.\n\n\
|
This performs benchmarks for 'gcc -O2 main.cpp' and 'clang -O2 main.cpp'.\n\n\
|
||||||
The option can be specified multiple times to run benchmarks for all \
|
The option can be specified multiple times to run benchmarks for all \
|
||||||
possible parameter combinations.\n"
|
possible parameter combinations.\n"
|
||||||
),
|
),
|
||||||
|
|||||||
+2
-4
@@ -158,9 +158,7 @@ impl<'a> Commands<'a> {
|
|||||||
});
|
});
|
||||||
let args: Vec<_> = args.map(|v| v.as_str()).collect::<Vec<_>>();
|
let args: Vec<_> = args.map(|v| v.as_str()).collect::<Vec<_>>();
|
||||||
let param_names_and_values: Vec<(&str, Vec<String>)> = args
|
let param_names_and_values: Vec<(&str, Vec<String>)> = args
|
||||||
.as_chunks::<2>()
|
.chunks_exact(2)
|
||||||
.0
|
|
||||||
.iter()
|
|
||||||
.map(|pair| {
|
.map(|pair| {
|
||||||
let name = pair[0];
|
let name = pair[0];
|
||||||
let list_str = pair[1];
|
let list_str = pair[1];
|
||||||
@@ -171,7 +169,7 @@ impl<'a> Commands<'a> {
|
|||||||
let duplicates =
|
let duplicates =
|
||||||
Self::find_duplicates(param_names_and_values.iter().map(|(name, _)| *name));
|
Self::find_duplicates(param_names_and_values.iter().map(|(name, _)| *name));
|
||||||
if !duplicates.is_empty() {
|
if !duplicates.is_empty() {
|
||||||
bail!("Duplicate parameter names: {}", duplicates.join(", "));
|
bail!("Duplicate parameter names: {}", &duplicates.join(", "));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,6 @@ use std::num::{self, ParseFloatError, ParseIntError};
|
|||||||
use rust_decimal::Error as DecimalError;
|
use rust_decimal::Error as DecimalError;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
|
||||||
#[error(transparent)]
|
|
||||||
pub struct ConsoleOutputError(pub std::io::Error);
|
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum ParameterScanError {
|
pub enum ParameterScanError {
|
||||||
#[error("Error while parsing parameter scan arguments ({0})")]
|
#[error("Error while parsing parameter scan arguments ({0})")]
|
||||||
|
|||||||
+3
-5
@@ -1,5 +1,5 @@
|
|||||||
use std::fs::{File, OpenOptions};
|
use std::fs::{File, OpenOptions};
|
||||||
use std::io::{self, Write};
|
use std::io::Write;
|
||||||
|
|
||||||
mod asciidoc;
|
mod asciidoc;
|
||||||
mod csv;
|
mod csv;
|
||||||
@@ -18,7 +18,6 @@ use self::orgmode::OrgmodeExporter;
|
|||||||
|
|
||||||
use crate::benchmark::benchmark_result::BenchmarkResult;
|
use crate::benchmark::benchmark_result::BenchmarkResult;
|
||||||
use crate::options::SortOrder;
|
use crate::options::SortOrder;
|
||||||
use crate::output::console_writeln;
|
|
||||||
use crate::util::units::Unit;
|
use crate::util::units::Unit;
|
||||||
|
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
@@ -145,9 +144,8 @@ impl ExportManager {
|
|||||||
}
|
}
|
||||||
ExportTarget::Stdout => {
|
ExportTarget::Stdout => {
|
||||||
if !intermediate {
|
if !intermediate {
|
||||||
let mut stdout = io::stdout().lock();
|
println!();
|
||||||
console_writeln!(stdout)?;
|
println!("{}", String::from_utf8(content()?).unwrap());
|
||||||
console_writeln!(stdout, "{}", String::from_utf8(content()?).unwrap())?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ impl MarkupExporter for OrgmodeExporter {
|
|||||||
format!(
|
format!(
|
||||||
"| {} | {} |\n",
|
"| {} | {} |\n",
|
||||||
cells.first().unwrap(),
|
cells.first().unwrap(),
|
||||||
cells[1..].join(" | ")
|
&cells[1..].join(" | ")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-16
@@ -4,12 +4,10 @@
|
|||||||
)]
|
)]
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::io::{self, Write};
|
|
||||||
|
|
||||||
use benchmark::scheduler::Scheduler;
|
use benchmark::scheduler::Scheduler;
|
||||||
use cli::get_cli_arguments;
|
use cli::get_cli_arguments;
|
||||||
use command::Commands;
|
use command::Commands;
|
||||||
use error::ConsoleOutputError;
|
|
||||||
use export::ExportManager;
|
use export::ExportManager;
|
||||||
use options::Options;
|
use options::Options;
|
||||||
|
|
||||||
@@ -46,29 +44,17 @@ fn run() -> Result<()> {
|
|||||||
|
|
||||||
let mut scheduler = Scheduler::new(&commands, &options, &export_manager);
|
let mut scheduler = Scheduler::new(&commands, &options, &export_manager);
|
||||||
scheduler.run_benchmarks()?;
|
scheduler.run_benchmarks()?;
|
||||||
scheduler.print_relative_speed_comparison()?;
|
scheduler.print_relative_speed_comparison();
|
||||||
scheduler.final_export()?;
|
scheduler.final_export()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn caused_by_broken_console_pipe(error: &anyhow::Error) -> bool {
|
|
||||||
error
|
|
||||||
.downcast_ref::<ConsoleOutputError>()
|
|
||||||
.is_some_and(|e| e.0.kind() == io::ErrorKind::BrokenPipe)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match run() {
|
match run() {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// Exit quietly when a reader stops consuming console output early.
|
eprintln!("{} {:#}", "Error:".red(), e);
|
||||||
if caused_by_broken_console_pipe(&e) {
|
|
||||||
std::process::exit(0);
|
|
||||||
}
|
|
||||||
// The write to stderr can itself fail if stderr is closed; the
|
|
||||||
// error message cannot be shown in that case anyway.
|
|
||||||
let _ = writeln!(io::stderr(), "{} {:#}", "Error:".red(), e);
|
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,3 @@
|
|||||||
pub mod format;
|
pub mod format;
|
||||||
pub mod progress_bar;
|
pub mod progress_bar;
|
||||||
pub mod warnings;
|
pub mod warnings;
|
||||||
|
|
||||||
/// Mark console write errors so broken pipes can be handled separately from file errors.
|
|
||||||
macro_rules! console_writeln {
|
|
||||||
($writer:expr $(, $($args:tt)*)?) => {
|
|
||||||
writeln!($writer $(, $($args)*)?)
|
|
||||||
.map_err($crate::error::ConsoleOutputError)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) use console_writeln;
|
|
||||||
@@ -4,5 +4,5 @@
|
|||||||
/// [1] Mytkowicz, 2009. Producing Wrong Data Without Doing Anything Obviously Wrong!.
|
/// [1] Mytkowicz, 2009. Producing Wrong Data Without Doing Anything Obviously Wrong!.
|
||||||
/// Sigplan Notices - SIGPLAN. 44. 265-276. 10.1145/1508284.1508275.
|
/// Sigplan Notices - SIGPLAN. 44. 265-276. 10.1145/1508284.1508275.
|
||||||
pub fn value() -> String {
|
pub fn value() -> String {
|
||||||
"X".repeat(rand::random_range(0..4096))
|
"X".repeat(rand::random::<usize>() % 4096usize)
|
||||||
}
|
}
|
||||||
+3
-1
@@ -1,7 +1,9 @@
|
|||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
use assert_cmd::cargo::CommandCargoExt;
|
||||||
|
|
||||||
pub fn hyperfine_raw_command() -> Command {
|
pub fn hyperfine_raw_command() -> Command {
|
||||||
let mut cmd = Command::new(assert_cmd::cargo::cargo_bin!("hyperfine"));
|
let mut cmd = Command::cargo_bin("hyperfine").unwrap();
|
||||||
cmd.current_dir("tests/");
|
cmd.current_dir("tests/");
|
||||||
cmd
|
cmd
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
mod common;
|
mod common;
|
||||||
use common::{hyperfine, hyperfine_raw_command};
|
use common::hyperfine;
|
||||||
|
|
||||||
use predicates::prelude::*;
|
use predicates::prelude::*;
|
||||||
|
|
||||||
@@ -33,47 +33,6 @@ fn one_run_is_supported() {
|
|||||||
.success();
|
.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Regression test: hyperfine must not panic when writing to a closed
|
|
||||||
/// stdout pipe (e.g. `hyperfine ... | head -n 1` or a downstream process
|
|
||||||
/// that terminates early). A `BrokenPipe` error should result in a quiet
|
|
||||||
/// exit with code 0 instead of a `println!` panic.
|
|
||||||
#[test]
|
|
||||||
fn exits_quietly_when_stdout_is_closed() {
|
|
||||||
use std::process::Stdio;
|
|
||||||
|
|
||||||
for args in [
|
|
||||||
vec!["--runs=1", "echo dummy benchmark"],
|
|
||||||
vec!["--runs=1", "--export-json=-", "echo dummy benchmark"],
|
|
||||||
vec!["--runs=1", "echo dummy benchmark", "echo second benchmark"],
|
|
||||||
] {
|
|
||||||
// A pipe whose read end has been closed before hyperfine is even
|
|
||||||
// started: every write to it will fail with `BrokenPipe`.
|
|
||||||
let (reader, writer) = std::io::pipe().expect("failed to create pipe");
|
|
||||||
drop(reader);
|
|
||||||
|
|
||||||
let output = hyperfine_raw_command()
|
|
||||||
.args(&args)
|
|
||||||
.stdout(writer)
|
|
||||||
.stderr(Stdio::piped())
|
|
||||||
.spawn()
|
|
||||||
.expect("failed to spawn hyperfine")
|
|
||||||
.wait_with_output()
|
|
||||||
.expect("failed to wait for hyperfine");
|
|
||||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
||||||
|
|
||||||
assert!(
|
|
||||||
!stderr.contains("panicked"),
|
|
||||||
"hyperfine panicked while writing to a closed pipe:\n{}",
|
|
||||||
stderr
|
|
||||||
);
|
|
||||||
assert!(
|
|
||||||
output.status.success(),
|
|
||||||
"hyperfine did not exit cleanly; stderr:\n{}",
|
|
||||||
stderr
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_run_commands_without_a_shell() {
|
fn can_run_commands_without_a_shell() {
|
||||||
hyperfine()
|
hyperfine()
|
||||||
|
|||||||
Reference in new issue
Block a user