README.md
This file
Path
README.md
239 lines · 7.4 KiB · Markdown
Last changed by
Fix clippy suggestionsDavid Peterbefore adoptionf5de548
History of this fileTake it
The walk stopped after 200 commits: lines older than 699d8ca point at it.
Add ARM binariesDavid Peterbefore adoption699d8ca
line 1why, one step back1# hyperfineUpdate README.mdDavid Peterbefore adoptiona044532
line 2why, one step back2[](https://github.com/sharkdp/hyperfine/actions/workflows/CICD.yml)Add ARM binariesDavid Peterbefore adoption699d8ca
lines 3–77why, one step back3[](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 benchmark2829To run a benchmark, you can simply call `hyperfine <command>...`. The argument(s) can be any30shell command. For example:31``` bash32hyperfine 'sleep 0.3'33```3435Hyperfine will automatically determine the number of runs to perform for each command. By default,36it will perform *at least* 10 benchmarking runs. To change this, you can use the `-m`/`--min-runs`37option:38``` bash39hyperfine --min-runs 5 'sleep 0.2' 'sleep 3.2'40```4142### Warmup runs and preparation commands4344If the program execution time is limited by disk I/O, the benchmarking results can be heavily45influenced by disk caches and whether they are cold or warm.4647If you want to run the benchmark on a warm cache, you can use the `-w`/`--warmup` option to perform48a certain number of program executions before the actual benchmark:49``` bash50hyperfine --warmup 3 'grep -R TODO *'51```5253Conversely, if you want to run the benchmark for a cold cache, you can use the `-p`/`--prepare`54option to run a special command before *each* timing run. For example, to clear harddisk caches55on Linux, you can run56``` bash57sync; echo 3 | sudo tee /proc/sys/vm/drop_caches58```59To use this specific command with Hyperfine, call `sudo -v` to temporarily gain sudo permissions60and then call:61``` bash62hyperfine --prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' 'grep -R TODO *'63```6465### Parameterized benchmarks6667If you want to run a benchmark where only a single parameter is varied (say, the number of68threads), you can use the `-P`/`--parameter-scan` option and call:69``` bash70hyperfine --prepare 'make clean' --parameter-scan num_threads 1 12 'make -j {num_threads}'71```72This also works with decimal numbers. The `-D`/`--parameter-step-size` option can be used73to control the step size:74``` bash75hyperfine --parameter-scan delay 0.3 0.7 -D 0.2 'sleep {delay}'76```77This runs `sleep 0.3`, `sleep 0.5` and `sleep 0.7`.Incorporate suggestions from reviewThiago Arraisbefore adoption8704e76
lines 78–97why, one step back7879### Shell functions and aliases8081If you are using bash, you can export shell functions to directly benchmark them with hyperfine:8283```84$ my_function() { sleep 1; }85$ export -f my_function86$ hyperfine my_function87```8889If you are using a different shell, or if you want to benchmark shell aliases, you may try to put90them in a separate file:9192```bash93echo 'my_function() { sleep 1 }' > /tmp/my_function.sh94echo 'alias my_alias="sleep 1"' > /tmp/my_alias.sh95hyperfine 'source /tmp/my_function.sh; eval my_function'96hyperfine 'source /tmp/my_alias.sh; eval my_alias'97```Add ARM binariesDavid Peterbefore adoption699d8ca
lines 98–122why, one step back9899### Export results100101Hyperfine has multiple options for exporting benchmark results: CSV, JSON, Markdown (see `--help`102text for details). To export results to Markdown, for example, you can use the `--export-markdown`103option that will create tables like this:104105| Command | Mean [s] | Min [s] | Max [s] | Relative |106|:---|---:|---:|---:|---:|107| `find . -iregex '.*[0-9]\.jpg$'` | 2.275 ± 0.046 | 2.243 | 2.397 | 9.79 ± 0.22 |108| `find . -iname '*[0-9].jpg'` | 1.427 ± 0.026 | 1.405 | 1.468 | 6.14 ± 0.13 |109| `fd -HI '.*[0-9]\.jpg$'` | 0.232 ± 0.002 | 0.230 | 0.236 | 1.00 |110111The JSON output is useful if you want to analyze the benchmark results in more detail. See the112[`scripts/`](https://github.com/sharkdp/hyperfine/tree/master/scripts) folder for some examples.113114## Installation115116[](https://repology.org/project/hyperfine/versions)117118### On Ubuntu119120Download the appropriate `.deb` package from the [Release page](https://github.com/sharkdp/hyperfine/releases)121and install it via `dpkg`:122```Prepare release v1.12David Peterbefore adoption93c1653
lines 123–124why, one step back123wget https://github.com/sharkdp/hyperfine/releases/download/v1.12.0/hyperfine_1.12.0_amd64.deb124sudo dpkg -i hyperfine_1.12.0_amd64.debAdd ARM binariesDavid Peterbefore adoption699d8ca
lines 125–148why, one step back125```126127### On Fedora128129On Fedora, hyperfine can be installed from the official repositories:130131```sh132dnf install hyperfine133```134135### On Alpine Linux136137On Alpine Linux, hyperfine can be installed [from the official repositories](https://pkgs.alpinelinux.org/packages?name=hyperfine):138```139apk add hyperfine140```141142### On Arch Linux143144On Arch Linux, hyperfine can be installed [from the official repositories](https://www.archlinux.org/packages/community/x86_64/hyperfine/):145```146pacman -S hyperfine147```148chore: add funtoo linux instructionsinvakid404before adoptionf5db783
lines 149–155why, one step back149### On Funtoo Linux150151On Funtoo Linux, hyperfine can be installed [from core-kit](https://github.com/funtoo/core-kit/tree/1.4-release/app-benchmarks/hyperfine):152```153emerge app-benchmarks/hyperfine154```155Add ARM binariesDavid Peterbefore adoption699d8ca
lines 156–205why, one step back156### On NixOS157158On NixOS, hyperfine can be installed [from the official repositories](https://nixos.org/nixos/packages.html?query=hyperfine):159```160nix-env -i hyperfine161```162163### On Void Linux164165Hyperfine can be installed via xbps166167```168xbps-install -S hyperfine169```170171### On macOS172173Hyperfine can be installed via [Homebrew](https://brew.sh):174```175brew install hyperfine176```177178Or you can install using [MacPorts](https://www.macports.org):179```180sudo port selfupdate181sudo port install hyperfine182```183184### On FreeBSD185186Hyperfine can be installed via pkg:187```188pkg install hyperfine189```190191### On OpenBSD192193```194doas pkg_add hyperfine195```196197### With conda198199Hyperfine can be installed via [`conda`](https://conda.io/en/latest/) from the [`conda-forge`](https://anaconda.org/conda-forge/hyperfine) channel:200```201conda install -c conda-forge hyperfine202```203204### With cargo (Linux, macOS, Windows)205Update install instructionsDavid Peterbefore adoptionf443195
line 206why, one step back206Hyperfine can be installed from source via [cargo](https://doc.rust-lang.org/cargo/):Add ARM binariesDavid Peterbefore adoption699d8ca
lines 207–210why, one step back207```208cargo install hyperfine209```210Fix clippy suggestionsDavid Peterbefore adoptionf5de548
line 211why, one step back211Make sure that you use Rust 1.57 or higher.Add ARM binariesDavid Peterbefore adoption699d8ca
lines 212–219why, one step back212213### From binaries (Linux, macOS, Windows)214215Download the corresponding archive from the [Release page](https://github.com/sharkdp/hyperfine/releases).216217## Alternative tools218219Hyperfine is inspired by [bench](https://github.com/Gabriel439/bench).Bump version to 1.11.0sharkdpbefore adoption118baa9
line 220why, one step back220Add ARM binariesDavid Peterbefore adoption699d8ca
lines 221–236why, one step back221## Integration with other tools222223[Chronologer](https://github.com/dandavison/chronologer) is a tool that uses `hyperfine` to224visualize changes in benchmark timings across your Git history.225226Make sure to check out the [`scripts` folder](https://github.com/sharkdp/hyperfine/tree/master/scripts)227in this repository for a set of tools to work with `hyperfine` benchmark results.228229## Origin of the name230231The name *hyperfine* was chosen in reference to the hyperfine levels of caesium 133 which play a crucial role in the232[definition of our base unit of time](https://en.wikipedia.org/wiki/Second#History_of_definition)233— the second.234235## License236Remove years from copyright noticeDavid Peterbefore adoptionb5bd054
line 237why, one step back237`hyperfine` is dual-licensed under the terms of the MIT License and the Apache License 2.0.Add ARM binariesDavid Peterbefore adoption699d8ca
line 238why, one step back238Remove years from copyright noticeDavid Peterbefore adoptionb5bd054
line 239why, one step back239See the [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT) files for details.