Skip to content

Commit 1fa959e

Browse files
committed
fix(sort): split locale benchmarks into separate files per locale
1 parent b263838 commit 1fa959e

File tree

5 files changed

+205
-210
lines changed

5 files changed

+205
-210
lines changed

src/uu/sort/Cargo.toml

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

6060
[[bench]]
61-
name = "sort_locale_bench"
61+
name = "sort_locale_c_bench"
62+
harness = false
63+
64+
[[bench]]
65+
name = "sort_locale_utf8_bench"
66+
harness = false
67+
68+
[[bench]]
69+
name = "sort_locale_de_bench"
6270
harness = false

src/uu/sort/benches/sort_locale_bench.rs

Lines changed: 0 additions & 209 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
fn main() {
49+
// Set C locale BEFORE any benchmarks run.
50+
// This must happen before divan::main() because the locale is cached
51+
// on first access via OnceLock and cannot be changed afterwards.
52+
unsafe {
53+
std::env::set_var("LC_ALL", "C");
54+
}
55+
divan::main();
56+
}
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)