Hyperfine: A Powerful Command-Line Benchmarking Tool
Hyperfine is a versatile command-line tool designed to benchmark the performance of various shell commands. This tool is especially useful for developers and systems administrators who need to compare the efficiency of different commands.
Key Features
Hyperfine offers several features that make it stand out:
- Statistical Analysis: It provides statistical analysis across multiple runs, ensuring accurate and reliable performance data.
- Arbitrary Shell Commands: Users can benchmark any shell command.
- Real-Time Feedback: It offers constant updates about the benchmark progress and estimates.
- Warmup Runs: Users can perform warmup runs before the actual benchmarking to ensure results are not skewed by initial cache filling.
- Cache Clearing: Commands to clear cache can be executed before each timing run, helpful for testing on cold caches.
- Outlier Detection: It identifies and accounts for statistical outliers due to interference or caching.
- Export Options: Results can be exported in various formats including CSV, JSON, Markdown, and AsciiDoc.
- Parameterized Benchmarks: Users can run benchmarks with varying parameters, like the number of threads.
- Cross-Platform Compatibility: Hyperfine supports multiple operating systems, including Linux, macOS, and Windows.
Usage Scenarios
To use hyperfine, one simply needs to provide the command to be benchmarked. For instance, to test a command that involves sleeping for 0.3 seconds, one would use:
hyperfine 'sleep 0.3'
For comparisons, multiple commands can be provided to see how they perform against each other:
hyperfine 'hexdump file' 'xxd file'
Users can manipulate several options to fine-tune their benchmarking strategy, such as specifying the number of runs with the --runs
option or performing warmup executions using --warmup
.
Advanced Benchmarking
Hyperfine supports advanced options for parameterized benchmarking, which allows users to scan parameters over a range or list to analyze how performance varies:
hyperfine --parameter-scan num_threads 1 12 'make -j {num_threads}'
Further, users can choose different shells to execute commands and avoid unnecessary overhead by using --shell
or bypass shell startup time correction with --shell=none
.
Results Export and Analysis
Hyperfine allows users to export benchmark results in various formats for deeper analysis. Markdown and JSON formats are supported, which are useful for documenting or programmatically analyzing the results.
Installation
Hyperfine is available on many systems and can be installed via package managers like apt
for Debian, brew
for macOS, and choco
for Windows, among others. It can also be built from source using Rust's cargo
package manager.
Integration and Tools
Hyperfine integrates well with other tools, such as Chronologer and Bencher, that visualize or track performance over time. The repository also includes scripts for analyzing benchmark data.
Behind the Name
The project name, Hyperfine, is inspired by the hyperfine levels of caesium 133, which are integral to the precise definition of a second.
Licensing and Contributions
Hyperfine is open-source, dual-licensed under MIT and Apache License 2.0, welcoming contributions and uses by the community.
With its robust features and user-friendly nature, Hyperfine stands as a vital tool for anyone looking to optimize command-line operations and applications for better performance outcomes.