Scripts2026年4月12日·1 分钟阅读

Hyperfine — Command-Line Benchmarking Tool

Hyperfine is a command-line benchmarking tool written in Rust. Run benchmarks with statistical analysis: multiple runs, warmup, outlier detection, comparison across commands, and export results. By the author of bat and fd.

SC
Script Depot · Community
快速使用

先拿来用,再决定要不要深挖

这里应该同时让用户和 Agent 知道第一步该复制什么、安装什么、落到哪里。

brew install hyperfine                      # macOS
cargo install hyperfine                     # Rust
sudo apt install hyperfine                  # Debian/Ubuntu
# Basic benchmark
hyperfine "sleep 0.5"

# Compare two commands
hyperfine "fd pattern" "find . -name pattern"

# With warmup runs
hyperfine --warmup 3 "cargo build"

# Multiple commands with labels
hyperfine \
  -n ripgrep "rg pattern" \
  -n grep "grep -r pattern ."

# Export results
hyperfine --export-markdown results.md "rg pattern" "grep -r pattern ."
hyperfine --export-json results.json "command"

# Parameter scan
hyperfine --parameter-scan threads 1 8 "cargo build -j {threads}"

# Preparation command (runs before each)
hyperfine --prepare "sync; echo 3 | sudo tee /proc/sys/vm/drop_caches" "cat large_file"
介绍

Hyperfine is a command-line benchmarking tool written in Rust by David Peter (also author of bat, fd, and pastel). Runs a command multiple times, performs statistical analysis, detects outliers, and outputs clean formatted results. The standard tool for CLI benchmarking.

What Hyperfine Does

  • Multiple runs — statistical significance (mean, stddev, min, max)
  • Warmup — configurable warmup runs before measurement
  • Outlier detection — flags and handles statistical outliers
  • Comparison — benchmark multiple commands side by side
  • Parameter scan — sweep a variable across values
  • Preparation — run setup before each benchmark iteration
  • Export — Markdown, JSON, CSV, AsciiDoc
  • Shell — configurable shell or no shell
  • Progress bar — visual progress during runs

Comparison

Tool Statistical Multi-cmd Export
Hyperfine Full Yes MD/JSON/CSV
time (shell) None No No
bench (Go) Basic No No
poop (Zig) Full Yes Terminal

常见问题 FAQ

Q: 需要多少次运行? A: 默认自动决定(至少 10 次或 3 秒)。加 --min-runs 50--max-runs 100 精确控制。

Q: 怎么排除缓存影响? A: 用 --prepare 在每次运行前清缓存;或 --warmup 5 让缓存稳定后再计时。

来源与致谢 Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产