Merge pull request #8939 from naoNao89/fix/sort-benchmark-variance
Some checks failed
CICD / Style/cargo-deny (push) Waiting to run
CICD / Style/deps (push) Waiting to run
CICD / Documentation/warnings (push) Waiting to run
CICD / MinRustV (push) Waiting to run
CICD / Separate Builds (push) Waiting to run
CICD / Dependencies (push) Waiting to run
CICD / Build/Makefile (push) Blocked by required conditions
CICD / Build/stable (push) Blocked by required conditions
CICD / Build/nightly (push) Blocked by required conditions
CICD / Binary sizes (push) Blocked by required conditions
CICD / Build (push) Blocked by required conditions
CICD / Tests/BusyBox test suite (push) Blocked by required conditions
CICD / Tests/Toybox test suite (push) Blocked by required conditions
CICD / Code Coverage (push) Waiting to run
CICD / Safe Traversal Security Check (push) Blocked by required conditions
CICD / Test all features separately (push) Blocked by required conditions
CICD / Build/SELinux (push) Blocked by required conditions
CICD / Build/SELinux-Stubs (Non-Linux) (push) Blocked by required conditions
GnuTests / Aggregate GNU test results (push) Blocked by required conditions
Android / Test builds (push) Waiting to run
Benchmarks / Run benchmarks (CodSpeed) (push) Waiting to run
FreeBSD / Style and Lint (push) Waiting to run
GnuTests / Run GNU tests (native) (push) Waiting to run
GnuTests / Run GNU tests (SELinux) (push) Waiting to run
Code Quality / Style/format (push) Waiting to run
Code Quality / Style/lint (push) Waiting to run
Code Quality / Style/spelling (push) Waiting to run
Code Quality / Style/toml (push) Waiting to run
Code Quality / Style/Python (push) Waiting to run
Code Quality / Pre-commit hooks (push) Waiting to run
Devcontainer / Verify devcontainer (push) Waiting to run
FreeBSD / Tests (push) Waiting to run
WSL2 / Test (push) Waiting to run
Check uudoc Documentation Generation / Verify uudoc generates correct documentation (push) Has been cancelled

Reduce variance in sort benchmarks by reusing temp file
This commit is contained in:
Sylvestre Ledru 2025-10-17 14:56:48 +02:00 committed by GitHub
commit a255a1f3db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,16 +14,17 @@ use uucore::benchmark::{run_util_function, setup_test_file, text_data};
fn sort_ascii_c_locale(bencher: Bencher) {
let data = text_data::generate_ascii_data_simple(100_000);
let file_path = setup_test_file(&data);
// Reuse the same output file across iterations to reduce filesystem variance
let output_file = NamedTempFile::new().unwrap();
let output_path = output_file.path().to_str().unwrap().to_string();
bencher.bench(|| {
unsafe {
env::set_var("LC_ALL", "C");
}
let output_file = NamedTempFile::new().unwrap();
let output_path = output_file.path().to_str().unwrap();
black_box(run_util_function(
uumain,
&["-o", output_path, file_path.to_str().unwrap()],
&["-o", &output_path, file_path.to_str().unwrap()],
));
});
}
@ -33,16 +34,17 @@ fn sort_ascii_c_locale(bencher: Bencher) {
fn sort_ascii_utf8_locale(bencher: Bencher) {
let data = text_data::generate_ascii_data_simple(200_000);
let file_path = setup_test_file(&data);
// Reuse the same output file across iterations to reduce filesystem variance
let output_file = NamedTempFile::new().unwrap();
let output_path = output_file.path().to_str().unwrap().to_string();
bencher.bench(|| {
unsafe {
env::set_var("LC_ALL", "en_US.UTF-8");
}
let output_file = NamedTempFile::new().unwrap();
let output_path = output_file.path().to_str().unwrap();
black_box(run_util_function(
uumain,
&["-o", output_path, file_path.to_str().unwrap()],
&["-o", &output_path, file_path.to_str().unwrap()],
));
});
}
@ -52,16 +54,17 @@ fn sort_ascii_utf8_locale(bencher: Bencher) {
fn sort_mixed_c_locale(bencher: Bencher) {
let data = text_data::generate_mixed_locale_data(50_000);
let file_path = setup_test_file(&data);
// Reuse the same output file across iterations to reduce filesystem variance
let output_file = NamedTempFile::new().unwrap();
let output_path = output_file.path().to_str().unwrap().to_string();
bencher.bench(|| {
unsafe {
env::set_var("LC_ALL", "C");
}
let output_file = NamedTempFile::new().unwrap();
let output_path = output_file.path().to_str().unwrap();
black_box(run_util_function(
uumain,
&["-o", output_path, file_path.to_str().unwrap()],
&["-o", &output_path, file_path.to_str().unwrap()],
));
});
}
@ -71,16 +74,17 @@ fn sort_mixed_c_locale(bencher: Bencher) {
fn sort_mixed_utf8_locale(bencher: Bencher) {
let data = text_data::generate_mixed_locale_data(50_000);
let file_path = setup_test_file(&data);
// Reuse the same output file across iterations to reduce filesystem variance
let output_file = NamedTempFile::new().unwrap();
let output_path = output_file.path().to_str().unwrap().to_string();
bencher.bench(|| {
unsafe {
env::set_var("LC_ALL", "en_US.UTF-8");
}
let output_file = NamedTempFile::new().unwrap();
let output_path = output_file.path().to_str().unwrap();
black_box(run_util_function(
uumain,
&["-o", output_path, file_path.to_str().unwrap()],
&["-o", &output_path, file_path.to_str().unwrap()],
));
});
}
@ -90,16 +94,17 @@ fn sort_mixed_utf8_locale(bencher: Bencher) {
fn sort_german_c_locale(bencher: Bencher) {
let data = text_data::generate_german_locale_data(50_000);
let file_path = setup_test_file(&data);
// Reuse the same output file across iterations to reduce filesystem variance
let output_file = NamedTempFile::new().unwrap();
let output_path = output_file.path().to_str().unwrap().to_string();
bencher.bench(|| {
unsafe {
env::set_var("LC_ALL", "C");
}
let output_file = NamedTempFile::new().unwrap();
let output_path = output_file.path().to_str().unwrap();
black_box(run_util_function(
uumain,
&["-o", output_path, file_path.to_str().unwrap()],
&["-o", &output_path, file_path.to_str().unwrap()],
));
});
}
@ -109,16 +114,17 @@ fn sort_german_c_locale(bencher: Bencher) {
fn sort_german_locale(bencher: Bencher) {
let data = text_data::generate_german_locale_data(50_000);
let file_path = setup_test_file(&data);
// Reuse the same output file across iterations to reduce filesystem variance
let output_file = NamedTempFile::new().unwrap();
let output_path = output_file.path().to_str().unwrap().to_string();
bencher.bench(|| {
unsafe {
env::set_var("LC_ALL", "de_DE.UTF-8");
}
let output_file = NamedTempFile::new().unwrap();
let output_path = output_file.path().to_str().unwrap();
black_box(run_util_function(
uumain,
&["-o", output_path, file_path.to_str().unwrap()],
&["-o", &output_path, file_path.to_str().unwrap()],
));
});
}
@ -128,16 +134,17 @@ fn sort_german_locale(bencher: Bencher) {
fn sort_random_strings(bencher: Bencher) {
let data = text_data::generate_random_strings(50_000, 50);
let file_path = setup_test_file(&data);
// Reuse the same output file across iterations to reduce filesystem variance
let output_file = NamedTempFile::new().unwrap();
let output_path = output_file.path().to_str().unwrap().to_string();
bencher.bench(|| {
unsafe {
env::set_var("LC_ALL", "en_US.UTF-8");
}
let output_file = NamedTempFile::new().unwrap();
let output_path = output_file.path().to_str().unwrap();
black_box(run_util_function(
uumain,
&["-o", output_path, file_path.to_str().unwrap()],
&["-o", &output_path, file_path.to_str().unwrap()],
));
});
}