mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-02 17:11:28 +00:00
Help text
This commit is contained in:
1 parent
15108de79e
commit
4f62157cc9
2 files changed
+39
-91
No files matched your search
+22
-11
@@ -55,17 +55,28 @@ fn build_command() -> Command {
|
|||||||
.long("metrics")
|
.long("metrics")
|
||||||
.value_name("PRESET|METRIC[:UNIT],…")
|
.value_name("PRESET|METRIC[:UNIT],…")
|
||||||
.default_value("default")
|
.default_value("default")
|
||||||
.help("Metrics to display, in order. The first is used for non-JSON exports. \
|
.hide_default_value(true)
|
||||||
Compare all commands with the first command. Presets: default (wall-clock \
|
.help("Performance metrics to measure, in order.\n\n\
|
||||||
time and peak RSS; wall-clock time only on Windows), time (wall-clock, total CPU, \
|
This is either a preset name, or a comma-separated list of metrics with optional units. \
|
||||||
user, and system time), all (all available metrics, skipping unavailable \
|
The first metric is used for non-JSON exports, \
|
||||||
measurements). All presets use automatic \
|
JSON always includes all collected metrics.\n\n\
|
||||||
units with wall-clock time first; use a preset on its own. Metrics: time_wall_clock, \
|
Presets (use one on its own):\n \
|
||||||
time_cpu (user + system), time_user, time_system, memory_peak_resident, cpu_cycles, instructions, \
|
default Wall-clock time and peak RSS\n \
|
||||||
cache_references, cache_misses, branch_misses. Optional units: ns/us/ms/s/min/h \
|
time Wall-clock, CPU, user, and system time\n \
|
||||||
for time, B/kB/MB/GB/TB/KiB/MiB/GiB/TiB for memory, count/k/M/B for counters \
|
all All available metrics\n\n\
|
||||||
(k = thousand, M = million, B = billion). Example: \
|
Presets use automatic units.\n\n\
|
||||||
--metrics memory_peak_resident:MiB,time_wall_clock:ms,instructions:B."),
|
Metrics and optional units:\n \
|
||||||
|
Time: time_wall_clock, time_cpu, time_user, time_system\n \
|
||||||
|
Units: ns, us, ms, s, min, h\n \
|
||||||
|
Memory: memory_peak_resident\n \
|
||||||
|
Units: B, kB, MB, GB, TB, KiB, MiB, GiB, TiB\n \
|
||||||
|
Counters: cpu_cycles, instructions, cache_references,\n \
|
||||||
|
cache_misses, branch_misses\n \
|
||||||
|
Units: count, k (thousand), M (million), B (billion)\n\n\
|
||||||
|
Examples:\n \
|
||||||
|
--metrics time_cpu,instructions\n \
|
||||||
|
--metrics memory_peak_resident:MiB,time_wall_clock:ms\n \
|
||||||
|
--metrics time"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("warmup")
|
Arg::new("warmup")
|
||||||
|
|||||||
+17
-80
@@ -37,51 +37,11 @@ fn json_snapshot_settings() -> insta::Settings {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn runs_successfully() {
|
fn runs_successfully() {
|
||||||
let output = hyperfine()
|
hyperfine()
|
||||||
.arg("--metrics=default")
|
|
||||||
.arg("--runs=2")
|
.arg("--runs=2")
|
||||||
.arg("echo dummy benchmark")
|
.arg("echo dummy benchmark")
|
||||||
.output()
|
|
||||||
.unwrap();
|
|
||||||
assert!(output.status.success(), "{:?}", output);
|
|
||||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
|
||||||
assert!(stdout.contains("Wall Time"));
|
|
||||||
assert!(!stdout.contains("User time"));
|
|
||||||
assert!(!stdout.contains("System time"));
|
|
||||||
assert_eq!(stdout.contains("Memory"), !cfg!(windows));
|
|
||||||
assert!(!stdout.contains("Change"));
|
|
||||||
assert!(!stdout.contains("Outliers"));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn metric_presets_select_available_metrics() {
|
|
||||||
for preset in ["time", "all"] {
|
|
||||||
let output = hyperfine_debug()
|
|
||||||
.arg(format!("--metrics={preset}"))
|
|
||||||
.args(["--style=basic", "--runs=2", "sleep 1", "sleep 2"])
|
|
||||||
.output()
|
|
||||||
.unwrap();
|
|
||||||
assert!(output.status.success(), "{:?}", output);
|
|
||||||
let stdout = String::from_utf8(output.stdout).unwrap();
|
|
||||||
assert_eq!(stdout.matches("Wall Time").count(), 2);
|
|
||||||
assert_eq!(stdout.matches("CPU time").count(), 2);
|
|
||||||
assert_eq!(stdout.matches("User time").count(), 2);
|
|
||||||
assert_eq!(stdout.matches("System time").count(), 2);
|
|
||||||
assert_eq!(stdout.contains("Memory"), preset == "all" && !cfg!(windows));
|
|
||||||
assert!(!stdout.contains("CPU cycles"));
|
|
||||||
assert!(!stdout.contains("Instructions"));
|
|
||||||
assert!(!stdout.contains("Change vs #1"));
|
|
||||||
assert!(stdout.contains("+100.0%"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Explicit selections still require the metric, unlike the `all` preset.
|
|
||||||
hyperfine_debug()
|
|
||||||
.args(["--metrics=instructions", "--runs=1", "sleep 1"])
|
|
||||||
.assert()
|
.assert()
|
||||||
.failure()
|
.success();
|
||||||
.stderr(predicate::str::contains(
|
|
||||||
"Metric 'instructions' is unavailable",
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -151,13 +111,23 @@ fn fails_with_zero_runs() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn min_runs_of_one_still_performs_one_run() {
|
fn min_runs_of_one_still_performs_one_run() {
|
||||||
hyperfine_debug()
|
let _settings = snapshot_settings().bind_to_scope();
|
||||||
|
assert_cmd_snapshot!(hyperfine_debug()
|
||||||
|
.arg("--style=basic")
|
||||||
|
.arg("--metrics=time_wall_clock")
|
||||||
.arg("--min-runs=1")
|
.arg("--min-runs=1")
|
||||||
.arg("--warmup=0")
|
.arg("--warmup=0")
|
||||||
.arg("sleep 4")
|
.arg("sleep 4"), @"
|
||||||
.assert()
|
success: true
|
||||||
.success()
|
exit_code: 0
|
||||||
.stdout(predicate::str::contains("Benchmark 1: sleep 4 (1 run)"));
|
----- stdout -----
|
||||||
|
Benchmark 1: sleep 4 (1 run)
|
||||||
|
Value
|
||||||
|
Wall Time 4.000 s
|
||||||
|
|
||||||
|
|
||||||
|
----- stderr -----
|
||||||
|
");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -848,39 +818,6 @@ fn comparison_and_markup_identify_first_command_as_reference() {
|
|||||||
assert!(row.ends_with("| N/A | |"), "{}", row);
|
assert!(row.ends_with("| N/A | |"), "{}", row);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn shows_name_of_first_command() {
|
|
||||||
let _settings = snapshot_settings().bind_to_scope();
|
|
||||||
assert_cmd_snapshot!(hyperfine_debug()
|
|
||||||
.arg("--metrics=time_wall_clock,memory_peak_resident")
|
|
||||||
.arg("--style=basic")
|
|
||||||
.arg("sleep 2.0")
|
|
||||||
.arg("--command-name=refabc123")
|
|
||||||
.arg("sleep 1.0")
|
|
||||||
.arg("sleep 3.0"), @"
|
|
||||||
success: true
|
|
||||||
exit_code: 0
|
|
||||||
----- stdout -----
|
|
||||||
Benchmark 1: refabc123 (10 runs)
|
|
||||||
mean ± σ min … max
|
|
||||||
Wall Time 2.000 s ± 0.000 s 2.000 s … 2.000 s
|
|
||||||
Memory 0.0 B ± 0.0 B 0.0 B … 0.0 B
|
|
||||||
|
|
||||||
Benchmark 2: sleep 1.0 (10 runs)
|
|
||||||
mean ± σ min … max
|
|
||||||
Wall Time 1.000 s ± 0.000 s 1.000 s … 1.000 s -50.0% (2.0x faster)
|
|
||||||
Memory 0.0 B ± 0.0 B 0.0 B … 0.0 B N/A
|
|
||||||
|
|
||||||
Benchmark 3: sleep 3.0 (10 runs)
|
|
||||||
mean ± σ min … max
|
|
||||||
Wall Time 3.000 s ± 0.000 s 3.000 s … 3.000 s +50.0% (1.5x slower)
|
|
||||||
Memory 0.0 B ± 0.0 B 0.0 B … 0.0 B N/A
|
|
||||||
|
|
||||||
|
|
||||||
----- stderr -----
|
|
||||||
");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn performs_all_benchmarks_in_parameter_scan() {
|
fn performs_all_benchmarks_in_parameter_scan() {
|
||||||
let _settings = snapshot_settings().bind_to_scope();
|
let _settings = snapshot_settings().bind_to_scope();
|
||||||
|
|||||||
Reference in new issue
Block a user