• Stars
    star
    18,256
  • Rank 1,449 (Top 0.03 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created almost 7 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A command-line benchmarking tool

hyperfine

CICD Version info 中文

A command-line benchmarking tool.

Demo: Benchmarking fd and find:

hyperfine

Sponsors

A special thank you goes to our biggest sponsor:

🐰 Bencher
Continuous Benchmarking: Catch performance regressions in CI


Track the results of your hyperfine benchmarks over time with Bencher.
Detect and prevent performance regressions before they make it to production.

Features

  • Statistical analysis across multiple runs.
  • Support for arbitrary shell commands.
  • Constant feedback about the benchmark progress and current estimates.
  • Warmup runs can be executed before the actual benchmark.
  • Cache-clearing commands can be set up before each timing run.
  • Statistical outlier detection to detect interference from other programs and caching effects.
  • Export results to various formats: CSV, JSON, Markdown, AsciiDoc.
  • Parameterized benchmarks (e.g. vary the number of threads).
  • Cross-platform

Usage

Basic benchmarks

To run a benchmark, you can simply call hyperfine <command>.... The argument(s) can be any shell command. For example:

hyperfine 'sleep 0.3'

Hyperfine will automatically determine the number of runs to perform for each command. By default, it will perform at least 10 benchmarking runs and measure for at least 3 seconds. To change this, you can use the -r/--runs option:

hyperfine --runs 5 'sleep 0.3'

If you want to compare the runtimes of different programs, you can pass multiple commands:

hyperfine 'hexdump file' 'xxd file'

Warmup runs and preparation commands

For programs that perform a lot of disk I/O, the benchmarking results can be heavily influenced by disk caches and whether they are cold or warm.

If you want to run the benchmark on a warm cache, you can use the -w/--warmup option to perform a certain number of program executions before the actual benchmark:

hyperfine --warmup 3 'grep -R TODO *'

Conversely, if you want to run the benchmark for a cold cache, you can use the -p/--prepare option to run a special command before each timing run. For example, to clear harddisk caches on Linux, you can run

sync; echo 3 | sudo tee /proc/sys/vm/drop_caches

To use this specific command with hyperfine, call sudo -v to temporarily gain sudo permissions and then call:

hyperfine --prepare 'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches' 'grep -R TODO *'

Parameterized benchmarks

If you want to run a series of benchmarks where a single parameter is varied (say, the number of threads), you can use the -P/--parameter-scan option and call:

hyperfine --prepare 'make clean' --parameter-scan num_threads 1 12 'make -j {num_threads}'

This also works with decimal numbers. The -D/--parameter-step-size option can be used to control the step size:

hyperfine --parameter-scan delay 0.3 0.7 -D 0.2 'sleep {delay}'

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 option:

hyperfine -L compiler gcc,clang '{compiler} -O2 main.cpp'

Intermediate shell

By default, commands are executed using a predefined shell (/bin/sh on Unix, cmd.exe on Windows). If you want to use a different shell, you can use the -S, --shell <SHELL> option:

hyperfine --shell zsh 'for i in {1..10000}; do echo test; done'

Note that hyperfine always corrects for the shell spawning time. To do this, it performs a calibration procedure where it runs the shell with an empty command (multiple times), to measure the startup time of the shell. It will then subtract this time from the total to show the actual time used by the command in question.

If you want to run a benchmark without an intermediate shell, you can use the -N or --shell=none option. This is helpful for very fast commands (< 5 ms) where the shell startup overhead correction would produce a significant amount of noise. Note that you cannot use shell syntax like * or ~ in this case.

hyperfine -N 'grep TODO /home/user'

Shell functions and aliases

If you are using bash, you can export shell functions to directly benchmark them with hyperfine:

my_function() { sleep 1; }
export -f my_function
hyperfine --shell=bash my_function

Otherwise, inline them into or source them from the benchmarked program:

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

Hyperfine has multiple options for exporting benchmark results to CSV, JSON, Markdown and other formats (see --help text for details).

Markdown

You can use the --export-markdown <file> option to create tables like the following:

Command Mean [s] Min [s] Max [s] Relative
find . -iregex '.*[0-9]\.jpg$' 2.275 ± 0.046 2.243 2.397 9.79 ± 0.22
find . -iname '*[0-9].jpg' 1.427 ± 0.026 1.405 1.468 6.14 ± 0.13
fd -HI '.*[0-9]\.jpg$' 0.232 ± 0.002 0.230 0.236 1.00

JSON

The JSON output is useful if you want to analyze the benchmark results in more detail. The scripts/ folder includes a lot of helpful Python programs to further analyze benchmark results and create helpful visualizations, like a histogram of runtimes or a whisker plot to compare multiple benchmarks:

Detailed benchmark flowchart

The following chart explains the execution order of various timing runs when using options like --warmup, --prepare <cmd>, --setup <cmd> or --cleanup <cmd>:

Installation

Packaging status

On Ubuntu

Download the appropriate .deb package from the Release page and install it via dpkg:

wget https://github.com/sharkdp/hyperfine/releases/download/v1.16.1/hyperfine_1.16.1_amd64.deb
sudo dpkg -i hyperfine_1.16.1_amd64.deb

On Fedora

On Fedora, hyperfine can be installed from the official repositories:

dnf install hyperfine

On Alpine Linux

On Alpine Linux, hyperfine can be installed from the official repositories:

apk add hyperfine

On Arch Linux

On Arch Linux, hyperfine can be installed from the official repositories:

pacman -S hyperfine

On Debian Linux

On Debian Linux, hyperfine can be installed from the testing repositories

apt install hyperfine

On Exherbo Linux

On Exherbo Linux, hyperfine can be installed [from the rust repositories](https://packages.debian.org/testing/main/hyperfine

cave resolve -x repository/rust
cave resolve -x hyperfine

On Funtoo Linux

On Funtoo Linux, hyperfine can be installed from core-kit:

emerge app-benchmarks/hyperfine

On NixOS

On NixOS, hyperfine can be installed from the official repositories:

nix-env -i hyperfine

On openSUSE

On openSUSE, hyperfine can be installed from the official repositories:

zypper install hyperfine

On Void Linux

Hyperfine can be installed via xbps

xbps-install -S hyperfine

On macOS

Hyperfine can be installed via Homebrew:

brew install hyperfine

Or you can install using MacPorts:

sudo port selfupdate
sudo port install hyperfine

On FreeBSD

Hyperfine can be installed via pkg:

pkg install hyperfine

On OpenBSD

doas pkg_add hyperfine

On Windows

Hyperfine can be installed via Chocolatey, Scoop, or Winget:

choco install hyperfine
scoop install hyperfine
winget install hyperfine

With conda

Hyperfine can be installed via conda from the conda-forge channel:

conda install -c conda-forge hyperfine

With cargo (Linux, macOS, Windows)

Hyperfine can be installed from source via cargo:

cargo install --locked hyperfine

Make sure that you use Rust 1.70 or newer.

From binaries (Linux, macOS, Windows)

Download the corresponding archive from the Release page.

Alternative tools

Hyperfine is inspired by bench.

Integration with other tools

Chronologer is a tool that uses hyperfine to visualize changes in benchmark timings across your Git history.

Bencher is a continuous benchmarking tool that supports hyperfine to track benchmarks and catch performance regressions in CI.

Make sure to check out the scripts folder in this repository for a set of tools to work with hyperfine benchmark results.

Origin of the name

The name hyperfine was chosen in reference to the hyperfine levels of caesium 133 which play a crucial role in the definition of our base unit of time — the second.

Citing hyperfine

Thank you for considering to cite hyperfine in your research work. Please see the information in the sidebar on how to properly cite hyperfine.

License

hyperfine is dual-licensed under the terms of the MIT License and the Apache License 2.0.

See the LICENSE-APACHE and LICENSE-MIT files for details.

More Repositories

1

bat

A cat(1) clone with wings.
Rust
48,695
star
2

fd

A simple, fast and user-friendly alternative to 'find'
Rust
33,228
star
3

hexyl

A command-line hex viewer
Rust
8,565
star
4

pastel

A command-line tool to generate, analyze, convert and manipulate colors
Rust
4,746
star
5

insect

High precision scientific calculator with support for physical units
PureScript
3,147
star
6

dbg-macro

A dbg(…) macro for C++
C++
2,719
star
7

cube-composer

A puzzle game inspired by functional programming
PureScript
1,967
star
8

vivid

A themeable LS_COLORS generator with a rich filetype datebase
Rust
1,479
star
9

shell-functools

Functional programming tools for the shell
Python
1,133
star
10

binocle

a graphical tool to visualize binary data
Rust
964
star
11

diskus

A minimal, fast alternative to 'du -sh'
Rust
936
star
12

numbat

A statically typed programming language for scientific computations with first class support for physical dimensions and units
Rust
734
star
13

great-puzzles

A curated list of great puzzles
484
star
14

purescript-flare

A special-purpose UI library for Purescript
PureScript
286
star
15

lscolors

A Rust library and tool to colorize paths using LS_COLORS
Rust
235
star
16

trigger

Run a user-defined command on file changes
Shell
181
star
17

bugreport

Rust library to collect system and environment information for bug reports
Rust
131
star
18

quizzity

A fast-paced geography quiz
JavaScript
125
star
19

curiosity

How far does your curiosity take you?
HTML
99
star
20

lucid

A simple mock-application for programs that work with child processes
Rust
86
star
21

parachuting-robots

An interactive version of a classic puzzle
PureScript
78
star
22

purescript-sparkle

Infer user interfaces from type signatures
PureScript
75
star
23

stack-inspector

A gdb command to inspect the size of objects on the stack
Python
62
star
24

painless

Painless parameter handling for easy exploration
C++
60
star
25

yinsh

A web-based version of the board game Yinsh
Haskell
59
star
26

purescript-isometric

Isometric rendering for PureScript
PureScript
58
star
27

pysh

Python-enhanced bash scripts
Python
58
star
28

purescript-quantities

Physical quantities and units
PureScript
53
star
29

minicpp

A REPL-style development environment for small C++ snippets
Shell
48
star
30

purescript-ctprelude

A Prelude with names from category theory
PureScript
48
star
31

qrnet

A neural network that decrypts QR codes
Python
43
star
32

riffle

A simple terminal pager (as a library)
Rust
41
star
33

config-files

A set of configuration files for vim, zsh, i3, ...
Python
37
star
34

content_inspector

Fast inspection of binary buffers to guess/determine the type of content
Rust
32
star
35

factorization-diagrams

Interactive factorization diagrams
HTML
27
star
36

argmax

Rust library to deal with "argument too long" errors
Rust
20
star
37

vacuum-robot-simulator

Simulation environment for an autonomous robot
Rust
19
star
38

sub

A command-line tool for string substitutions (RustLab 2019 workshop)
Rust
16
star
39

purescript-format

Type-safe, printf-style formatting for PureScript
PureScript
15
star
40

PaperLocator

Citation parsing to quickly access publications
JavaScript
14
star
41

purescript-decimals

Arbitrary precision numbers for PureScript
PureScript
13
star
42

flare-example

Quick start project for purescript-flare
PureScript
11
star
43

fd-benchmarks

Benchmarks for 'fd'
Shell
10
star
44

tinytag

tinytag is a "URL" shortener for your filesystem
Python
10
star
45

purescript-flaredoc

Interactive documentation with Flare
PureScript
8
star
46

phd-thesis

LaTeX sources for my PhD thesis
TeX
7
star
47

level11

7
star
48

GPE-Solver

Split-step solver for the 3D (dipolar) Gross-Pitaevskii equation
C++
7
star
49

Pack-Zack

A tag-based manager for packing lists
CSS
7
star
50

latex-report

A clean and simple LaTeX template for reports
TeX
7
star
51

dp

Personal website about some of my open source projects, board games and mountainbiking.
HTML
5
star
52

cs231n

My solutions to the CS231n assignments
Jupyter Notebook
4
star
53

imdb-ratings

Statistical analysis of my IMDB movie ratings
Jupyter Notebook
3
star
54

purescript-pairs

Datatype and functions for pairs of values
PureScript
3
star
55

zehntausend

A solver for the dice game Zehntausend
Haskell
3
star
56

gnuplot-mm

GnuPlot bindings for Mathematica
Mathematica
2
star
57

talk-moderne-programmiersprachen

JavaScript
2
star
58

rock-paper-scissors

Interactive regex puzzle
HTML
2
star
59

purescript-gametree

Algorithms for two-player zero-sum games
PureScript
2
star
60

snake-factory

A work-in-progress game with monadic parsers and snakes
PureScript
1
star
61

gomoku

Five in a row
PureScript
1
star