Skip to content

Commit ecf3353

Browse files
bench(sort): add general numeric benchmark (#10101)
--------- Co-authored-by: Sylvestre Ledru <[email protected]>
1 parent baf18ab commit ecf3353

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/uu/sort/benches/sort_bench.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,32 @@ fn sort_numeric(bencher: Bencher, num_lines: usize) {
128128
});
129129
}
130130

131+
/// Benchmark general numeric sorting (-g) with decimal and exponent notation
132+
#[divan::bench(args = [200_000])]
133+
fn sort_general_numeric(bencher: Bencher, num_lines: usize) {
134+
let mut data = Vec::new();
135+
136+
// Generate numeric data with decimal points and exponents
137+
for i in 0..num_lines {
138+
let int_part = (i * 13) % 100_000;
139+
let frac_part = (i * 7) % 1000;
140+
let exp = (i % 5) as i32 - 2; // -2..=2
141+
let sign = if i % 2 == 0 { "" } else { "-" };
142+
data.extend_from_slice(format!("{sign}{int_part}.{frac_part:03}e{exp:+}\n").as_bytes());
143+
}
144+
145+
let file_path = setup_test_file(&data);
146+
let output_file = NamedTempFile::new().unwrap();
147+
let output_path = output_file.path().to_str().unwrap();
148+
149+
bencher.bench(|| {
150+
black_box(run_util_function(
151+
uumain,
152+
&["-g", "-o", output_path, file_path.to_str().unwrap()],
153+
));
154+
});
155+
}
156+
131157
/// Benchmark reverse sorting with locale-aware data
132158
#[divan::bench(args = [500_000])]
133159
fn sort_reverse_locale(bencher: Bencher, num_lines: usize) {

0 commit comments

Comments
 (0)