• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H17-Oct-2021-348301

cargo-crates/H03-May-2022-887,960737,808

doc/H17-Oct-2021-216215

scripts/H17-Oct-2021-312238

src/H17-Oct-2021-3,6632,950

tests/H17-Oct-2021-215188

.gitignoreH A D17-Oct-202121 42

CHANGELOG.mdH A D17-Oct-20219.2 KiB278178

Cargo.lockH A D17-Oct-202120.4 KiB825735

Cargo.tomlH A D17-Oct-20211 KiB4941

LICENSE-APACHEH A D17-Oct-202111.1 KiB202169

LICENSE-MITH A D17-Oct-20211.1 KiB2217

README.mdH A D17-Oct-20217.3 KiB240173

build.rsH A D17-Oct-2021579 2116

README.md

1# hyperfine
2[![CICD](https://github.com/sharkdp/hyperfine/actions/workflows/CICD.yml/badge.svg)](https://github.com/sharkdp/hyperfine/actions/workflows/CICD.yml)
3[![Version info](https://img.shields.io/crates/v/hyperfine.svg)](https://crates.io/crates/hyperfine)
4[中文](https://github.com/chinanf-boy/hyperfine-zh)
5
6A command-line benchmarking tool.
7
8**Demo**: Benchmarking [`fd`](https://github.com/sharkdp/fd) and
9[`find`](https://www.gnu.org/software/findutils/):
10
11![hyperfine](https://i.imgur.com/z19OYxE.gif)
12
13## Features
14
15* 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-platform
24
25## Usage
26
27### Basic benchmark
28
29To run a benchmark, you can simply call `hyperfine <command>...`. The argument(s) can be any
30shell command. For example:
31``` bash
32hyperfine 'sleep 0.3'
33```
34
35Hyperfine 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``` bash
39hyperfine --min-runs 5 'sleep 0.2' 'sleep 3.2'
40```
41
42### Warmup runs and preparation commands
43
44If the program execution time is limited by disk I/O, the benchmarking results can be heavily
45influenced by disk caches and whether they are cold or warm.
46
47If you want to run the benchmark on a warm cache, you can use the `-w`/`--warmup` option to perform
48a certain number of program executions before the actual benchmark:
49``` bash
50hyperfine --warmup 3 'grep -R TODO *'
51```
52
53Conversely, 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 caches
55on Linux, you can run
56``` bash
57sync; echo 3 | sudo tee /proc/sys/vm/drop_caches
58```
59To use this specific command with Hyperfine, call `sudo -v` to temporarily gain sudo permissions
60and then call:
61``` bash
62hyperfine --prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' 'grep -R TODO *'
63```
64
65### Parameterized benchmarks
66
67If you want to run a benchmark where only a single parameter is varied (say, the number of
68threads), you can use the `-P`/`--parameter-scan` option and call:
69``` bash
70hyperfine --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 used
73to control the step size:
74``` bash
75hyperfine --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`.
78
79### Shell functions and aliases
80
81If you are using bash, you can export shell functions to directly benchmark them with hyperfine:
82
83```
84$ my_function() { sleep 1; }
85$ export -f my_function
86$ hyperfine my_function
87```
88
89If you are using a different shell, or if you want to benchmark shell aliases, you may try to put
90them in a separate file:
91
92```bash
93echo 'my_function() { sleep 1 }' > /tmp/my_function.sh
94echo 'alias my_alias="sleep 1"' > /tmp/my_alias.sh
95hyperfine 'source /tmp/my_function.sh; eval my_function'
96hyperfine 'source /tmp/my_alias.sh; eval my_alias'
97```
98
99### Export results
100
101Hyperfine 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:
104
105| 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 |
110
111The JSON output is useful if you want to analyze the benchmark results in more detail. See the
112[`scripts/`](https://github.com/sharkdp/hyperfine/tree/master/scripts) folder for some examples.
113
114## Installation
115
116[![Packaging status](https://repology.org/badge/vertical-allrepos/hyperfine.svg)](https://repology.org/project/hyperfine/versions)
117
118### On Ubuntu
119
120Download the appropriate `.deb` package from the [Release page](https://github.com/sharkdp/hyperfine/releases)
121and install it via `dpkg`:
122```
123wget https://github.com/sharkdp/hyperfine/releases/download/v1.12.0/hyperfine_1.12.0_amd64.deb
124sudo dpkg -i hyperfine_1.12.0_amd64.deb
125```
126
127### On Fedora
128
129On Fedora, hyperfine can be installed from the official repositories:
130
131```sh
132dnf install hyperfine
133```
134
135### On Alpine Linux
136
137On Alpine Linux, hyperfine can be installed [from the official repositories](https://pkgs.alpinelinux.org/packages?name=hyperfine):
138```
139apk add hyperfine
140```
141
142### On Arch Linux
143
144On Arch Linux, hyperfine can be installed [from the official repositories](https://www.archlinux.org/packages/community/x86_64/hyperfine/):
145```
146pacman -S hyperfine
147```
148
149### On Funtoo Linux
150
151On 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/hyperfine
154```
155
156### On NixOS
157
158On NixOS, hyperfine can be installed [from the official repositories](https://nixos.org/nixos/packages.html?query=hyperfine):
159```
160nix-env -i hyperfine
161```
162
163### On Void Linux
164
165Hyperfine can be installed via xbps
166
167```
168xbps-install -S hyperfine
169```
170
171### On macOS
172
173Hyperfine can be installed via [Homebrew](https://brew.sh):
174```
175brew install hyperfine
176```
177
178Or you can install using [MacPorts](https://www.macports.org):
179```
180sudo port selfupdate
181sudo port install hyperfine
182```
183
184### On FreeBSD
185
186Hyperfine can be installed via pkg:
187```
188pkg install hyperfine
189```
190
191### On OpenBSD
192
193```
194doas pkg_add hyperfine
195```
196
197### With conda
198
199Hyperfine 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 hyperfine
202```
203
204### With cargo (Linux, macOS, Windows)
205
206Hyperfine can be installed via [cargo](https://doc.rust-lang.org/cargo/):
207```
208cargo install hyperfine
209```
210
211Make sure that you use Rust 1.46 or higher.
212
213### From binaries (Linux, macOS, Windows)
214
215Download the corresponding archive from the [Release page](https://github.com/sharkdp/hyperfine/releases).
216
217## Alternative tools
218
219Hyperfine is inspired by [bench](https://github.com/Gabriel439/bench).
220
221## Integration with other tools
222
223[Chronologer](https://github.com/dandavison/chronologer) is a tool that uses `hyperfine` to
224visualize changes in benchmark timings across your Git history.
225
226Make 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.
228
229## Origin of the name
230
231The name *hyperfine* was chosen in reference to the hyperfine levels of caesium 133 which play a crucial role in the
232[definition of our base unit of time](https://en.wikipedia.org/wiki/Second#History_of_definition)
233— the second.
234
235## License
236
237`hyperfine` is dual-licensed under the terms of the MIT License and the Apache License 2.0.
238
239See the [LICENSE-APACHE](LICENSE-APACHE) and [LICENSE-MIT](LICENSE-MIT) files for details.
240