Skip to content

Commit 4e3a860

Browse files
authored
fix(sort): split locale benchmarks into separate files per locale (#9914)
1 parent a297d26 commit 4e3a860

File tree

5 files changed

+223
-190
lines changed

5 files changed

+223
-190
lines changed

src/uu/sort/Cargo.toml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,13 @@ name = "sort_bench"
6060
harness = false
6161

6262
[[bench]]
63-
name = "sort_locale_bench"
63+
name = "sort_locale_c_bench"
64+
harness = false
65+
66+
[[bench]]
67+
name = "sort_locale_utf8_bench"
68+
harness = false
69+
70+
[[bench]]
71+
name = "sort_locale_de_bench"
6472
harness = false

src/uu/sort/benches/sort_locale_bench.rs

Lines changed: 0 additions & 189 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// This file is part of the uutils coreutils package.
2+
//
3+
// For the full copyright and license information, please view the LICENSE
4+
// file that was distributed with this source code.
5+
6+
//! Benchmarks for sort with C locale (fast byte-wise comparison).
7+
//!
8+
//! Note: The locale is set in main() BEFORE any benchmark runs because
9+
//! the locale is cached on first access via OnceLock and cannot be changed afterwards.
10+
11+
use divan::{Bencher, black_box};
12+
use tempfile::NamedTempFile;
13+
use uu_sort::uumain;
14+
use uucore::benchmark::{run_util_function, setup_test_file, text_data};
15+
16+
/// Benchmark ASCII-only data sorting with C locale (byte comparison)
17+
#[divan::bench]
18+
fn sort_ascii_c_locale(bencher: Bencher) {
19+
let data = text_data::generate_ascii_data_simple(100_000);
20+
let file_path = setup_test_file(&data);
21+
let output_file = NamedTempFile::new().unwrap();
22+
let output_path = output_file.path().to_str().unwrap().to_string();
23+
24+
bencher.bench(|| {
25+
black_box(run_util_function(
26+
uumain,
27+
&["-o", &output_path, file_path.to_str().unwrap()],
28+
));
29+
});
30+
}
31+
32+
/// Benchmark mixed ASCII/Unicode data with C locale (byte comparison)
33+
#[divan::bench]
34+
fn sort_mixed_c_locale(bencher: Bencher) {
35+
let data = text_data::generate_mixed_locale_data(50_000);
36+
let file_path = setup_test_file(&data);
37+
let output_file = NamedTempFile::new().unwrap();
38+
let output_path = output_file.path().to_str().unwrap().to_string();
39+
40+
bencher.bench(|| {
41+
black_box(run_util_function(
42+
uumain,
43+
&["-o", &output_path, file_path.to_str().unwrap()],
44+
));
45+
});
46+
}
47+
48+
/// Benchmark German locale-specific data with C locale (byte comparison)
49+
#[divan::bench]
50+
fn sort_german_c_locale(bencher: Bencher) {
51+
let data = text_data::generate_german_locale_data(50_000);
52+
let file_path = setup_test_file(&data);
53+
let output_file = NamedTempFile::new().unwrap();
54+
let output_path = output_file.path().to_str().unwrap().to_string();
55+
56+
bencher.bench(|| {
57+
black_box(run_util_function(
58+
uumain,
59+
&["-o", &output_path, file_path.to_str().unwrap()],
60+
));
61+
});
62+
}
63+
64+
fn main() {
65+
// Set C locale BEFORE any benchmarks run.
66+
// This must happen before divan::main() because the locale is cached
67+
// on first access via OnceLock and cannot be changed afterwards.
68+
unsafe {
69+
std::env::set_var("LC_ALL", "C");
70+
}
71+
divan::main();
72+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// This file is part of the uutils coreutils package.
2+
//
3+
// For the full copyright and license information, please view the LICENSE
4+
// file that was distributed with this source code.
5+
6+
//! Benchmarks for sort with German locale (de_DE.UTF-8 collation).
7+
//!
8+
//! Note: The locale is set in main() BEFORE any benchmark runs because
9+
//! the locale is cached on first access via OnceLock and cannot be changed afterwards.
10+
11+
use divan::{Bencher, black_box};
12+
use tempfile::NamedTempFile;
13+
use uu_sort::uumain;
14+
use uucore::benchmark::{run_util_function, setup_test_file, text_data};
15+
16+
/// Benchmark German locale-specific data with German locale
17+
#[divan::bench]
18+
fn sort_german_de_locale(bencher: Bencher) {
19+
let data = text_data::generate_german_locale_data(50_000);
20+
let file_path = setup_test_file(&data);
21+
let output_file = NamedTempFile::new().unwrap();
22+
let output_path = output_file.path().to_str().unwrap().to_string();
23+
24+
bencher.bench(|| {
25+
black_box(run_util_function(
26+
uumain,
27+
&["-o", &output_path, file_path.to_str().unwrap()],
28+
));
29+
});
30+
}
31+
32+
fn main() {
33+
// Set German locale BEFORE any benchmarks run.
34+
// This must happen before divan::main() because the locale is cached
35+
// on first access via OnceLock and cannot be changed afterwards.
36+
unsafe {
37+
std::env::set_var("LC_ALL", "de_DE.UTF-8");
38+
}
39+
divan::main();
40+
}

0 commit comments

Comments
 (0)