From 44e6914e88d7937199327d4b9c1947343d3e4e2d Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 1 Jul 2026 20:14:00 +0200 Subject: [PATCH 1/3] df: redirect stdout in df_with_path benchmark to cut timing variance --- src/uu/df/Cargo.toml | 3 +++ src/uu/df/benches/df_bench.rs | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/uu/df/Cargo.toml b/src/uu/df/Cargo.toml index 813ab93a202..dcee0e254b0 100644 --- a/src/uu/df/Cargo.toml +++ b/src/uu/df/Cargo.toml @@ -33,6 +33,9 @@ divan = { workspace = true } tempfile = { workspace = true } uucore = { workspace = true, features = ["benchmark"] } +[target.'cfg(unix)'.dev-dependencies] +rustix = { workspace = true, features = ["stdio"] } + [[bin]] name = "df" path = "src/main.rs" diff --git a/src/uu/df/benches/df_bench.rs b/src/uu/df/benches/df_bench.rs index b9453dd0c1e..f678f7f7b9a 100644 --- a/src/uu/df/benches/df_bench.rs +++ b/src/uu/df/benches/df_bench.rs @@ -37,6 +37,28 @@ fn df_deep_directory(bencher: Bencher) { env::set_current_dir(original_dir).unwrap(); } +#[cfg(unix)] +#[divan::bench] +fn df_with_path(bencher: Bencher) { + use rustix::stdio::dup2_stdout; + + let temp_dir = TempDir::new().unwrap(); + let temp_path_str = temp_dir.path().to_str().unwrap(); + let stdout_bak = rustix::io::dup(rustix::stdio::stdout()).unwrap(); + let devnull = fs::OpenOptions::new() + .write(true) + .open("/dev/null") + .unwrap(); + + bencher.bench_local(|| { + dup2_stdout(&devnull).unwrap(); + black_box(run_util_function(uumain, &[temp_path_str])); + }); + + dup2_stdout(&stdout_bak).unwrap(); +} + +#[cfg(not(unix))] #[divan::bench] fn df_with_path(bencher: Bencher) { let temp_dir = TempDir::new().unwrap(); From 8903b6d5e34b0c9cda39d00d83ae1bcbce36891b Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Wed, 1 Jul 2026 20:52:00 +0200 Subject: [PATCH 2/3] sort: enlarge C/UTF-8 locale ascii datasets to cut timing variance --- src/uu/sort/benches/sort_locale_c_bench.rs | 2 +- src/uu/sort/benches/sort_locale_utf8_bench.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uu/sort/benches/sort_locale_c_bench.rs b/src/uu/sort/benches/sort_locale_c_bench.rs index 378a2abb9ac..8335992716c 100644 --- a/src/uu/sort/benches/sort_locale_c_bench.rs +++ b/src/uu/sort/benches/sort_locale_c_bench.rs @@ -16,7 +16,7 @@ use uucore::benchmark::{run_util_function, setup_test_file, text_data}; /// Benchmark ASCII-only data sorting with C locale (byte comparison) #[divan::bench] fn sort_ascii_c_locale(bencher: Bencher) { - let data = text_data::generate_ascii_data_simple(100_000); + let data = text_data::generate_ascii_data_simple(2_000_000); let file_path = setup_test_file(&data); let output_file = NamedTempFile::new().unwrap(); let output_path = output_file.path().to_str().unwrap().to_string(); diff --git a/src/uu/sort/benches/sort_locale_utf8_bench.rs b/src/uu/sort/benches/sort_locale_utf8_bench.rs index 2885118c091..81e39c8971f 100644 --- a/src/uu/sort/benches/sort_locale_utf8_bench.rs +++ b/src/uu/sort/benches/sort_locale_utf8_bench.rs @@ -16,7 +16,7 @@ use uucore::benchmark::{run_util_function, setup_test_file, text_data}; /// Benchmark ASCII-only data sorting with UTF-8 locale #[divan::bench] fn sort_ascii_utf8_locale(bencher: Bencher) { - let data = text_data::generate_ascii_data_simple(100_000); + let data = text_data::generate_ascii_data_simple(1_500_000); let file_path = setup_test_file(&data); let output_file = NamedTempFile::new().unwrap(); let output_path = output_file.path().to_str().unwrap().to_string(); From b2e47dadb08aa6ac9993b4baa1a353ae65befd44 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 4 Jul 2026 18:32:22 +0200 Subject: [PATCH 3/3] df: fix out-of-order Cargo.toml tables (target deps before dev-dependencies) --- src/uu/df/Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/uu/df/Cargo.toml b/src/uu/df/Cargo.toml index dcee0e254b0..eaa9571f9f2 100644 --- a/src/uu/df/Cargo.toml +++ b/src/uu/df/Cargo.toml @@ -25,14 +25,14 @@ unicode-width = { workspace = true } thiserror = { workspace = true } fluent = { workspace = true } -[target.'cfg(unix)'.dependencies] -rustix = { workspace = true, features = ["fs"] } - [dev-dependencies] divan = { workspace = true } tempfile = { workspace = true } uucore = { workspace = true, features = ["benchmark"] } +[target.'cfg(unix)'.dependencies] +rustix = { workspace = true, features = ["fs"] } + [target.'cfg(unix)'.dev-dependencies] rustix = { workspace = true, features = ["stdio"] }