README.md
This file
Path
README.md
355 lines · 10.9 KiB · Markdown
Last changed by
Update READMEDavid Peterbefore adoption92cc4f2
History of this fileTake it
The walk stopped after 200 commits: lines older than 790e1bf point at it.
Bump version to 1.15David Peterbefore adoption790e1bf
lines 1–12why, one step back1# hyperfine2[](https://github.com/sharkdp/hyperfine/actions/workflows/CICD.yml)3[](https://crates.io/crates/hyperfine)4[中文](https://github.com/chinanf-boy/hyperfine-zh)56A command-line benchmarking tool.78**Demo**: Benchmarking [`fd`](https://github.com/sharkdp/fd) and9[`find`](https://www.gnu.org/software/findutils/):101112Update READMEDavid Peterbefore adoption92cc4f2
lines 13–24why, one step back13### Sponsors1415A special *thank you* goes to our biggest <a href="doc/sponsors.md">sponsor</a>:<br>1617<a href="https://www.warp.dev/hyperfine">18 <img src="doc/sponsors/warp-logo.png" width="200" alt="Warp">19 <br>20 <strong>Warp, the intelligent terminal</strong>21 <br>22 <sub>Available on MacOS, Linux, Windows</sub>23</a>24Bump version to 1.15David Peterbefore adoption790e1bf
lines 25–42why, one step back25## Features2627* Statistical analysis across multiple runs.28* Support for arbitrary shell commands.29* Constant feedback about the benchmark progress and current estimates.30* Warmup runs can be executed before the actual benchmark.31* Cache-clearing commands can be set up before each timing run.32* Statistical outlier detection to detect interference from other programs and caching effects.33* Export results to various formats: CSV, JSON, Markdown, AsciiDoc.34* Parameterized benchmarks (e.g. vary the number of threads).35* Cross-platform3637## Usage3839### Basic benchmarks4041To run a benchmark, you can simply call `hyperfine <command>...`. The argument(s) can be any42shell command. For example:Fix Shell functions and aliases sexion in READMEнабbefore adoption32e80fb
line 43why, one step back43```shBump version to 1.15David Peterbefore adoption790e1bf
lines 44–49why, one step back44hyperfine 'sleep 0.3'45```4647Hyperfine will automatically determine the number of runs to perform for each command. By default,48it will perform *at least* 10 benchmarking runs and measure for at least 3 seconds. To change this,49you can use the `-r`/`--runs` option:Fix Shell functions and aliases sexion in READMEнабbefore adoption32e80fb
line 50why, one step back50```shBump version to 1.15David Peterbefore adoption790e1bf
lines 51–54why, one step back51hyperfine --runs 5 'sleep 0.3'52```5354If you want to compare the runtimes of different programs, you can pass multiple commands:Fix Shell functions and aliases sexion in READMEнабbefore adoption32e80fb
line 55why, one step back55```shBump version to 1.15David Peterbefore adoption790e1bf
lines 56–65why, one step back56hyperfine 'hexdump file' 'xxd file'57```5859### Warmup runs and preparation commands6061For programs that perform a lot of disk I/O, the benchmarking results can be heavily influenced62by disk caches and whether they are cold or warm.6364If you want to run the benchmark on a warm cache, you can use the `-w`/`--warmup` option to65perform a certain number of program executions before the actual benchmark:Fix Shell functions and aliases sexion in READMEнабbefore adoption32e80fb
line 66why, one step back66```shBump version to 1.15David Peterbefore adoption790e1bf
lines 67–72why, one step back67hyperfine --warmup 3 'grep -R TODO *'68```6970Conversely, if you want to run the benchmark for a cold cache, you can use the `-p`/`--prepare`71option to run a special command before *each* timing run. For example, to clear harddisk caches72on Linux, you can runFix Shell functions and aliases sexion in READMEнабbefore adoption32e80fb
line 73why, one step back73```shBump version to 1.15David Peterbefore adoption790e1bf
lines 74–77why, one step back74sync; echo 3 | sudo tee /proc/sys/vm/drop_caches75```76To use this specific command with hyperfine, call `sudo -v` to temporarily gain sudo permissions77and then call:Fix Shell functions and aliases sexion in READMEнабbefore adoption32e80fb
line 78why, one step back78```shBump version to 1.15David Peterbefore adoption790e1bf
lines 79–85why, one step back79hyperfine --prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' 'grep -R TODO *'80```8182### Parameterized benchmarks8384If you want to run a series of benchmarks where a single parameter is varied (say, the number of85threads), you can use the `-P`/`--parameter-scan` option and call:Fix Shell functions and aliases sexion in READMEнабbefore adoption32e80fb
line 86why, one step back86```shBump version to 1.15David Peterbefore adoption790e1bf
lines 87–90why, one step back87hyperfine --prepare 'make clean' --parameter-scan num_threads 1 12 'make -j {num_threads}'88```89This also works with decimal numbers. The `-D`/`--parameter-step-size` option can be used90to control the step size:Fix Shell functions and aliases sexion in READMEнабbefore adoption32e80fb
line 91why, one step back91```shBump version to 1.15David Peterbefore adoption790e1bf
lines 92–105why, one step back92hyperfine --parameter-scan delay 0.3 0.7 -D 0.2 'sleep {delay}'93```94This runs `sleep 0.3`, `sleep 0.5` and `sleep 0.7`.9596For non-numeric parameters, you can also supply a list of values with the `-L`/`--parameter-list`97option:98```99hyperfine -L compiler gcc,clang '{compiler} -O2 main.cpp'100```101102### Intermediate shell103104By default, commands are executed using a predefined shell (`/bin/sh` on Unix, `cmd.exe` on Windows).105If you want to use a different shell, you can use the `-S, --shell <SHELL>` option:Fix Shell functions and aliases sexion in READMEнабbefore adoption32e80fb
line 106why, one step back106```shBump version to 1.15David Peterbefore adoption790e1bf
lines 107–116why, one step back107hyperfine --shell zsh 'for i in {1..10000}; do echo test; done'108```109110Note that hyperfine always *corrects for the shell spawning time*. To do this, it performs a calibration111procedure where it runs the shell with an empty command (multiple times), to measure the startup time112of the shell. It will then subtract this time from the total to show the actual time used by the command113in question.114115If you want to run a benchmark *without an intermediate shell*, you can use the `-N` or `--shell=none`116option. This is helpful for very fast commands (< 5 ms) where the shell startup overhead correction wouldFix a typoMateusz Piotrowskibefore adoption6c007ff
line 117why, one step back117produce a significant amount of noise. Note that you cannot use shell syntax like `*` or `~` in this case.Bump version to 1.15David Peterbefore adoption790e1bf
lines 118–124why, one step back118```119hyperfine -N 'grep TODO /home/user'120```121122123### Shell functions and aliases124Revert to prev. sentenceDavid Peterbefore adoption69c91f5
line 125why, one step back125If you are using bash, you can export shell functions to directly benchmark them with hyperfine:Bump version to 1.15David Peterbefore adoption790e1bf
line 126why, one step back126Fix Shell functions and aliases sexion in READMEнабbefore adoption32e80fb
lines 127–130why, one step back127```bash128my_function() { sleep 1; }129export -f my_function130hyperfine --shell=bash my_functionBump version to 1.15David Peterbefore adoption790e1bf
lines 131–132why, one step back131```132Fix Shell functions and aliases sexion in READMEнабbefore adoption32e80fb
line 133why, one step back133Otherwise, inline them into or source them from the benchmarked program:Bump version to 1.15David Peterbefore adoption790e1bf
line 134why, one step back134Fix Shell functions and aliases sexion in READMEнабbefore adoption32e80fb
lines 135–137why, one step back135```sh136hyperfine 'my_function() { sleep 1; }; my_function'137Bump version to 1.15David Peterbefore adoption790e1bf
line 138why, one step back138echo 'alias my_alias="sleep 1"' > /tmp/my_alias.shFix Shell functions and aliases sexion in READMEнабbefore adoption32e80fb
line 139why, one step back139hyperfine '. /tmp/my_alias.sh; my_alias'Bump version to 1.15David Peterbefore adoption790e1bf
lines 140–146why, one step back140```141142### Exporting results143144Hyperfine has multiple options for exporting benchmark results to CSV, JSON, Markdown and other145formats (see `--help` text for details).146Fix Shell functions and aliases sexion in READMEнабbefore adoption32e80fb
line 147why, one step back147#### MarkdownBump version to 1.15David Peterbefore adoption790e1bf
lines 148–177why, one step back148149You can use the `--export-markdown <file>` option to create tables like the following:150151| Command | Mean [s] | Min [s] | Max [s] | Relative |152|:---|---:|---:|---:|---:|153| `find . -iregex '.*[0-9]\.jpg$'` | 2.275 ± 0.046 | 2.243 | 2.397 | 9.79 ± 0.22 |154| `find . -iname '*[0-9].jpg'` | 1.427 ± 0.026 | 1.405 | 1.468 | 6.14 ± 0.13 |155| `fd -HI '.*[0-9]\.jpg$'` | 0.232 ± 0.002 | 0.230 | 0.236 | 1.00 |156157#### JSON158159The JSON output is useful if you want to analyze the benchmark results in more detail. The160[`scripts/`](https://github.com/sharkdp/hyperfine/tree/master/scripts) folder includes a lot161of helpful Python programs to further analyze benchmark results and create helpful162visualizations, like a histogram of runtimes or a whisker plot to compare163multiple benchmarks:164165|  |  |166|---:|---:|167168169### Detailed benchmark flowchart170171The following chart explains the execution order of various timing runs when using options172like `--warmup`, `--prepare <cmd>`, `--setup <cmd>` or `--cleanup <cmd>`:173174175176## Installation177Update README.mdDavid Peterbefore adoption12fec42
line 178why, one step back178[](https://repology.org/project/hyperfine/versions)Bump version to 1.15David Peterbefore adoption790e1bf
lines 179–184why, one step back179180### On Ubuntu181182Download the appropriate `.deb` package from the [Release page](https://github.com/sharkdp/hyperfine/releases)183and install it via `dpkg`:184```Fix version in READMEDavid Peterbefore adoption87d77c8
lines 185–186why, one step back185wget https://github.com/sharkdp/hyperfine/releases/download/v1.19.0/hyperfine_1.19.0_amd64.deb186sudo dpkg -i hyperfine_1.19.0_amd64.debBump version to 1.15David Peterbefore adoption790e1bf
lines 187–205why, one step back187```188189### On Fedora190191On Fedora, hyperfine can be installed from the official repositories:192193```sh194dnf install hyperfine195```196197### On Alpine Linux198199On Alpine Linux, hyperfine can be installed [from the official repositories](https://pkgs.alpinelinux.org/packages?name=hyperfine):200```201apk add hyperfine202```203204### On Arch Linux205Fix the Arch url to repo in README.mdAymenbefore adoptionc6a6dcc
line 206why, one step back206On Arch Linux, hyperfine can be installed [from the official repositories](https://archlinux.org/packages/extra/x86_64/hyperfine/):Bump version to 1.15David Peterbefore adoption790e1bf
lines 207–210why, one step back207```208pacman -S hyperfine209```210Update README.mdbaarkerloungerbefore adoptione23b325
lines 211–212why, one step back211### On Debian Linux212Fix typos README.mdAntonin Décimobefore adoption824aafb
line 213why, one step back213On Debian Linux, hyperfine can be installed [from the testing repositories](https://packages.debian.org/testing/main/hyperfine):Update README.mdbaarkerloungerbefore adoptione23b325
lines 214–217why, one step back214```215apt install hyperfine216```217docs: add Exherbo Linux in README.md setup instructionsDavid Legrandbefore adoptiond712879
lines 218–219why, one step back218### On Exherbo Linux219Fix typos README.mdAntonin Décimobefore adoption824aafb
line 220why, one step back220On Exherbo Linux, hyperfine can be installed [from the rust repositories](https://gitlab.exherbo.org/exherbo/rust/-/tree/master/packages/sys-apps/hyperfine):docs: add Exherbo Linux in README.md setup instructionsDavid Legrandbefore adoptiond712879
lines 221–225why, one step back221```222cave resolve -x repository/rust223cave resolve -x hyperfine224```225Bump version to 1.15David Peterbefore adoption790e1bf
lines 226–239why, one step back226### On Funtoo Linux227228On Funtoo Linux, hyperfine can be installed [from core-kit](https://github.com/funtoo/core-kit/tree/1.4-release/app-benchmarks/hyperfine):229```230emerge app-benchmarks/hyperfine231```232233### On NixOS234235On NixOS, hyperfine can be installed [from the official repositories](https://nixos.org/nixos/packages.html?query=hyperfine):236```237nix-env -i hyperfine238```239docs: Add flox installBryan Honofbefore adoption4a00f18
lines 240–247why, one step back240### On Flox241242On Flox, hyperfine can be installed as follows.243```244flox install hyperfine245```246Hyperfine's version in Flox follows that of Nix.247Add openSUSE installation instructionsShun Sakaibefore adoption7696523
lines 248–254why, one step back248### On openSUSE249250On openSUSE, hyperfine can be installed [from the official repositories](https://software.opensuse.org/package/hyperfine):251```252zypper install hyperfine253```254Bump version to 1.15David Peterbefore adoption790e1bf
lines 255–288why, one step back255### On Void Linux256257Hyperfine can be installed via xbps258259```260xbps-install -S hyperfine261```262263### On macOS264265Hyperfine can be installed via [Homebrew](https://brew.sh):266```267brew install hyperfine268```269270Or you can install using [MacPorts](https://www.macports.org):271```272sudo port selfupdate273sudo port install hyperfine274```275276### On FreeBSD277278Hyperfine can be installed via pkg:279```280pkg install hyperfine281```282283### On OpenBSD284285```286doas pkg_add hyperfine287```288Add Windows installation instructionssitiombefore adoption36d6155
lines 289–301why, one step back289### On Windows290291Hyperfine can be installed via [Chocolatey](https://community.chocolatey.org/packages/hyperfine), [Scoop](https://scoop.sh/#/apps?q=hyperfine&s=0&d=1&o=true&id=8f7c10f75ecf5f9e42a862c615257328e2f70f61), or [Winget](https://github.com/microsoft/winget-pkgs/tree/master/manifests/s/sharkdp/hyperfine):292```293choco install hyperfine294```295```296scoop install hyperfine297```298```299winget install hyperfine300```301Bump version to 1.15David Peterbefore adoption790e1bf
lines 302–312why, one step back302### With conda303304Hyperfine can be installed via [`conda`](https://conda.io/en/latest/) from the [`conda-forge`](https://anaconda.org/conda-forge/hyperfine) channel:305```306conda install -c conda-forge hyperfine307```308309### With cargo (Linux, macOS, Windows)310311Hyperfine can be installed from source via [cargo](https://doc.rust-lang.org/cargo/):312```Suggest to use `cargo install --locked`, see #605 andDavid Peterbefore adoptionc4b54b0
line 313why, one step back313cargo install --locked hyperfineBump version to 1.15David Peterbefore adoption790e1bf
lines 314–315why, one step back314```315Update dependenciesDavid Peterbefore adoption2efc633
line 316why, one step back316Make sure that you use Rust 1.76 or newer.Bump version to 1.15David Peterbefore adoption790e1bf
lines 317–323why, one step back317318### From binaries (Linux, macOS, Windows)319320Download the corresponding archive from the [Release page](https://github.com/sharkdp/hyperfine/releases).321322## Alternative tools323Fix a link to benchMateusz Piotrowskibefore adoption4c993b5
line 324why, one step back324Hyperfine is inspired by [bench](https://github.com/Gabriella439/bench).Bump version to 1.15David Peterbefore adoption790e1bf
lines 325–330why, one step back325326## Integration with other tools327328[Chronologer](https://github.com/dandavison/chronologer) is a tool that uses `hyperfine` to329visualize changes in benchmark timings across your Git history.330Add Bencher to list of toolsEverett Pompeiibefore adoptionc5089d8
lines 331–333why, one step back331[Bencher](https://github.com/bencherdev/bencher) is a continuous benchmarking tool that supports `hyperfine` to332track benchmarks and catch performance regressions in CI.333Add link to VenzLars Kappertbefore adoption3b09185
lines 334–336why, one step back334Drop hyperfine JSON outputs onto the [Venz](https://try.venz.dev) chart to visualize the results,335and manage hyperfine configurations.336Bump version to 1.15David Peterbefore adoption790e1bf
lines 337–345why, one step back337Make sure to check out the [`scripts` folder](https://github.com/sharkdp/hyperfine/tree/master/scripts)338in this repository for a set of tools to work with `hyperfine` benchmark results.339340## Origin of the name341342The name *hyperfine* was chosen in reference to the hyperfine levels of caesium 133 which play a crucial role in the343[definition of our base unit of time](https://en.wikipedia.org/wiki/Second#History_of_definition)344— the second.345Add citing guide, as per issue #566wrenbefore adoption64f26d2
lines 346–347why, one step back346## Citing hyperfine347Move information to CITATION.cff fileDavid Peterbefore adoption779d425
lines 348–349why, one step back348Thank you for considering to cite hyperfine in your research work. Please see the information349in the sidebar on how to properly cite hyperfine.Add citing guide, as per issue #566wrenbefore adoption64f26d2
line 350why, one step back350Bump version to 1.15David Peterbefore adoption790e1bf
lines 351–355why, one step back351## License352353`hyperfine` is dual-licensed under the terms of the MIT License and the Apache License 2.0.354355See the [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT) files for details.