README.md
This file
Path
README.md
354 lines · 11.2 KiB · Markdown
Last changed by
Merge pull request #900 from ded-furby/docs/hyperfine-iteration-readmeDavid Peterbefore adoptiona2d7094
History of this fileTake it
The walk stopped after 200 commits: lines older than ca9e29a point at it.
Fix pipeline!David Peterbefore adoptionca9e29a
lines 1–35why, 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/):10111213## Features1415* Statistical analysis across multiple runs.16* Support for arbitrary shell commands.17* Constant feedback about the benchmark progress and current estimates.18* Warmup runs can be executed before the actual benchmark.19* Cache-clearing commands can be set up before each timing run.20* Statistical outlier detection to detect interference from other programs and caching effects.21* Export results to various formats: CSV, JSON, Markdown, AsciiDoc.22* Parameterized benchmarks (e.g. vary the number of threads).23* Cross-platform2425## Usage2627### Basic benchmarks2829To run a benchmark, you can simply call `hyperfine <command>...`. The argument(s) can be any30shell command. For example:31```sh32hyperfine 'sleep 0.3'33```3435Hyperfine will automatically determine the number of runs to perform for each command. By default,Describe the default benchmark duration as an estimate (#941)David Peterbefore adoption0bb209e
lines 36–38why, one step back36it will perform *at least* 10 benchmarking runs and estimate a run count targeting roughly373 seconds, including shell overhead and preparation and conclusion commands. To set an exact38number of runs, you can use the `-r`/`--runs` option:Fix pipeline!David Peterbefore adoptionca9e29a
lines 39–59why, one step back39```sh40hyperfine --runs 5 'sleep 0.3'41```4243If you want to compare the runtimes of different programs, you can pass multiple commands:44```sh45hyperfine 'hexdump file' 'xxd file'46```4748### Warmup runs and preparation commands4950For programs that perform a lot of disk I/O, the benchmarking results can be heavily influenced51by disk caches and whether they are cold or warm.5253If you want to run the benchmark on a warm cache, you can use the `-w`/`--warmup` option to54perform a certain number of program executions before the actual benchmark:55```sh56hyperfine --warmup 3 'grep -R TODO *'57```5859Conversely, if you want to run the benchmark for a cold cache, you can use the `-p`/`--prepare`Describe the Linux cache-clearing example accurately (#945)David Peterbefore adoption0c5701b
lines 60–61why, one step back60option to run a special command before *each* timing run. For example, to clear Linux filesystem caches,61you can runFix pipeline!David Peterbefore adoptionca9e29a
lines 62–87why, one step back62```sh63sync; echo 3 | sudo tee /proc/sys/vm/drop_caches64```65To use this specific command with hyperfine, call `sudo -v` to temporarily gain sudo permissions66and then call:67```sh68hyperfine --prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' 'grep -R TODO *'69```7071### Parameterized benchmarks7273If you want to run a series of benchmarks where a single parameter is varied (say, the number of74threads), you can use the `-P`/`--parameter-scan` option and call:75```sh76hyperfine --prepare 'make clean' --parameter-scan num_threads 1 12 'make -j {num_threads}'77```78This also works with decimal numbers. The `-D`/`--parameter-step-size` option can be used79to control the step size:80```sh81hyperfine --parameter-scan delay 0.3 0.7 -D 0.2 'sleep {delay}'82```83This runs `sleep 0.3`, `sleep 0.5` and `sleep 0.7`.8485For non-numeric parameters, you can also supply a list of values with the `-L`/`--parameter-list`86option:87```Use C++ compiler drivers in parameter-list examples (#936)David Peterbefore adoption1c92587
line 88why, one step back88hyperfine -L compiler g++,clang++ '{compiler} -O2 main.cpp'Fix pipeline!David Peterbefore adoptionca9e29a
lines 89–90why, one step back89```90Merge pull request #899 from xfocus3/docs/compare-git-branches-606David Peterbefore adoption88a9150
lines 91–100why, one step back91A common use case is comparing the same command across multiple Git branches. Use `--setup`92to switch branches once before each set of timing runs, so the branch switch is not part of93the measured command:94```sh95hyperfine \96 --parameter-list branch main,performance-improvements \97 --setup 'git switch {branch}' \98 'python main.py'99```100Merge pull request #900 from ded-furby/docs/hyperfine-iteration-readmeDavid Peterbefore adoptiona2d7094
lines 101–106why, one step back101If you need a unique value for each individual run of a benchmark command, hyperfine also exposes102the zero-based `$HYPERFINE_ITERATION` environment variable inside the benchmarked command itself:103```sh104hyperfine 'my-command > output-${HYPERFINE_ITERATION}.log'105```106Fix pipeline!David Peterbefore adoptionca9e29a
lines 107–108why, one step back107### Intermediate shell108Merge pull request #942 from sharkdp/codex/docs-default-shellDavid Peterbefore adoptiond75c16d
line 109why, one step back109By default, commands are executed using `sh` on Unix (resolved through `PATH`) or `cmd.exe` on Windows.Fix pipeline!David Peterbefore adoptionca9e29a
lines 110–123why, one step back110If you want to use a different shell, you can use the `-S, --shell <SHELL>` option:111```sh112hyperfine --shell zsh 'for i in {1..10000}; do echo test; done'113```114115Note that hyperfine always *corrects for the shell spawning time*. To do this, it performs a calibration116procedure where it runs the shell with an empty command (multiple times), to measure the startup time117of the shell. It will then subtract this time from the total to show the actual time used by the command118in question.119120If you want to run a benchmark *without an intermediate shell*, you can use the `-N` or `--shell=none`121option. This is helpful for very fast commands (< 5 ms) where the shell startup overhead correction would122produce a significant amount of noise. Note that you cannot use shell syntax like `*` or `~` in this case.123```Use a file in the no-shell grep example (#937)David Peterbefore adoption7dc13e4
line 124why, one step back124hyperfine -N 'grep -R TODO /home/user'Fix pipeline!David Peterbefore adoptionca9e29a
lines 125–127why, one step back125```126127Remove shell alias example from READMEDavid Peterbefore adoption148632c
line 128why, one step back128### Shell functionsFix pipeline!David Peterbefore adoptionca9e29a
lines 129–137why, one step back129130If you are using bash, you can export shell functions to directly benchmark them with hyperfine:131132```bash133my_function() { sleep 1; }134export -f my_function135hyperfine --shell=bash my_function136```137Remove shell alias example from READMEDavid Peterbefore adoption148632c
line 138why, one step back138Otherwise, inline the function into the benchmarked command:Fix pipeline!David Peterbefore adoptionca9e29a
lines 139–179why, one step back139140```sh141hyperfine 'my_function() { sleep 1; }; my_function'142```143144### Exporting results145146Hyperfine has multiple options for exporting benchmark results to CSV, JSON, Markdown and other147formats (see `--help` text for details).148149#### Markdown150151You can use the `--export-markdown <file>` option to create tables like the following:152153| Command | Mean [s] | Min [s] | Max [s] | Relative |154|:---|---:|---:|---:|---:|155| `find . -iregex '.*[0-9]\.jpg$'` | 2.275 ± 0.046 | 2.243 | 2.397 | 9.79 ± 0.22 |156| `find . -iname '*[0-9].jpg'` | 1.427 ± 0.026 | 1.405 | 1.468 | 6.14 ± 0.13 |157| `fd -HI '.*[0-9]\.jpg$'` | 0.232 ± 0.002 | 0.230 | 0.236 | 1.00 |158159#### JSON160161The JSON output is useful if you want to analyze the benchmark results in more detail. The162[`scripts/`](https://github.com/sharkdp/hyperfine/tree/master/scripts) folder includes a lot163of helpful Python programs to further analyze benchmark results and create helpful164visualizations, like a histogram of runtimes or a whisker plot to compare165multiple benchmarks:166167|  |  |168|---:|---:|169170171### Detailed benchmark flowchart172173The following chart explains the execution order of various timing runs when using options174like `--warmup`, `--prepare <cmd>`, `--setup <cmd>` or `--cleanup <cmd>`:175176177178## Installation179Update README.mdDavid Peterbefore adoption12fec42
line 180why, one step back180[](https://repology.org/project/hyperfine/versions)Fix pipeline!David Peterbefore adoptionca9e29a
lines 181–183why, one step back181182### On Ubuntu183Update ubuntu install instructionsRavi Kant Sharmabefore adoption6b8fa5f
lines 184–189why, one step back184On Ubuntu, hyperfine can be installed [from the official repositories](https://launchpad.net/ubuntu/+source/rust-hyperfine):185```186apt install hyperfine187```188189Alternatively, 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`:Fix pipeline!David Peterbefore adoptionca9e29a
line 190why, one step back190```Bump version to 1.20.0David Peterbefore adoption975fe10
lines 191–192why, one step back191wget https://github.com/sharkdp/hyperfine/releases/download/v1.20.0/hyperfine_1.20.0_amd64.deb192sudo dpkg -i hyperfine_1.20.0_amd64.debFix pipeline!David Peterbefore adoptionca9e29a
lines 193–211why, one step back193```194195### On Fedora196197On Fedora, hyperfine can be installed from the official repositories:198199```sh200dnf install hyperfine201```202203### On Alpine Linux204205On Alpine Linux, hyperfine can be installed [from the official repositories](https://pkgs.alpinelinux.org/packages?name=hyperfine):206```207apk add hyperfine208```209210### On Arch Linux211Fix the Arch url to repo in README.mdAymenbefore adoptionc6a6dcc
line 212why, one step back212On Arch Linux, hyperfine can be installed [from the official repositories](https://archlinux.org/packages/extra/x86_64/hyperfine/):Fix pipeline!David Peterbefore adoptionca9e29a
lines 213–218why, one step back213```214pacman -S hyperfine215```216217### On Debian Linux218Debian: Hyperfine is now available in stableSylvestre Ledrubefore adoptionae4c807
line 219why, one step back219On Debian Linux, hyperfine can be installed [from the official repositories](https://packages.debian.org/hyperfine):Fix pipeline!David Peterbefore adoptionca9e29a
lines 220–223why, one step back220```221apt install hyperfine222```223docs: add Exherbo Linux in README.md setup instructionsDavid Legrandbefore adoptiond712879
lines 224–225why, one step back224### On Exherbo Linux225Fix typos README.mdAntonin Décimobefore adoption824aafb
line 226why, one step back226On 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 227–231why, one step back227```228cave resolve -x repository/rust229cave resolve -x hyperfine230```231Fix pipeline!David Peterbefore adoptionca9e29a
lines 232–238why, one step back232### On NixOS233234On NixOS, hyperfine can be installed [from the official repositories](https://nixos.org/nixos/packages.html?query=hyperfine):235```236nix-env -i hyperfine237```238docs: Add flox installBryan Honofbefore adoption4a00f18
lines 239–246why, one step back239### On Flox240241On Flox, hyperfine can be installed as follows.242```243flox install hyperfine244```245Hyperfine's version in Flox follows that of Nix.246Add openSUSE installation instructionsShun Sakaibefore adoption7696523
lines 247–253why, one step back247### On openSUSE248249On openSUSE, hyperfine can be installed [from the official repositories](https://software.opensuse.org/package/hyperfine):250```251zypper install hyperfine252```253Fix pipeline!David Peterbefore adoptionca9e29a
lines 254–314why, one step back254### On Void Linux255256Hyperfine can be installed via xbps257258```259xbps-install -S hyperfine260```261262### On macOS263264Hyperfine can be installed via [Homebrew](https://brew.sh):265```266brew install hyperfine267```268269Or you can install using [MacPorts](https://www.macports.org):270```271sudo port selfupdate272sudo port install hyperfine273```274275### On FreeBSD276277Hyperfine can be installed via pkg:278```279pkg install hyperfine280```281282### On OpenBSD283284```285doas pkg_add hyperfine286```287288### On Windows289290Hyperfine 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):291```292choco install hyperfine293```294```295scoop install hyperfine296```297```298winget install hyperfine299```300301### With conda302303Hyperfine can be installed via [`conda`](https://conda.io/en/latest/) from the [`conda-forge`](https://anaconda.org/conda-forge/hyperfine) channel:304```305conda install -c conda-forge hyperfine306```307308### With cargo (Linux, macOS, Windows)309310Hyperfine can be installed from source via [cargo](https://doc.rust-lang.org/cargo/):311```312cargo install --locked hyperfine313```314Dependency and MSRV update (#934)David Peterbefore adoption4d073e0
line 315why, one step back315Make sure that you use Rust 1.97 or newer.Fix pipeline!David Peterbefore adoptionca9e29a
lines 316–329why, one step back316317### From binaries (Linux, macOS, Windows)318319Download the corresponding archive from the [Release page](https://github.com/sharkdp/hyperfine/releases).320321## Alternative tools322323Hyperfine is inspired by [bench](https://github.com/Gabriella439/bench).324325## Integration with other tools326327[Chronologer](https://github.com/dandavison/chronologer) is a tool that uses `hyperfine` to328visualize changes in benchmark timings across your Git history.329Add Bencher to list of toolsEverett Pompeiibefore adoptionc5089d8
lines 330–332why, one step back330[Bencher](https://github.com/bencherdev/bencher) is a continuous benchmarking tool that supports `hyperfine` to331track benchmarks and catch performance regressions in CI.332Add link to VenzLars Kappertbefore adoption3b09185
lines 333–335why, one step back333Drop hyperfine JSON outputs onto the [Venz](https://try.venz.dev) chart to visualize the results,334and manage hyperfine configurations.335Fix pipeline!David Peterbefore adoptionca9e29a
lines 336–346why, one step back336Make sure to check out the [`scripts` folder](https://github.com/sharkdp/hyperfine/tree/master/scripts)337in this repository for a set of tools to work with `hyperfine` benchmark results.338339## Origin of the name340341The name *hyperfine* was chosen in reference to the hyperfine levels of caesium 133 which play a crucial role in the342[definition of our base unit of time](https://en.wikipedia.org/wiki/Second#History_of_definition)343— the second.344345## Citing hyperfine346Fix documentation typos and man-page formatting (#935)David Peterbefore adoption62cfbf0
line 347why, one step back347Thank you for considering citing hyperfine in your research work. Please see the informationFix pipeline!David Peterbefore adoptionca9e29a
lines 348–354why, one step back348in the sidebar on how to properly cite hyperfine.349350## License351352`hyperfine` is dual-licensed under the terms of the MIT License and the Apache License 2.0.353354See the [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT) files for details.