Skip to content

Commit 7a988bf

Browse files
committed
split: add benchmarks
1 parent 5143999 commit 7a988bf

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

src/uu/split/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,12 @@ fluent = { workspace = true }
2727
[[bin]]
2828
name = "split"
2929
path = "src/main.rs"
30+
31+
[dev-dependencies]
32+
divan = { workspace = true }
33+
tempfile = { workspace = true }
34+
uucore = { workspace = true, features = ["benchmark"] }
35+
36+
[[bench]]
37+
name = "split_bench"
38+
harness = false
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
use divan::{Bencher, black_box};
7+
use tempfile::TempDir;
8+
use uu_split::uumain;
9+
use uucore::benchmark::{run_util_function, setup_test_file, text_data};
10+
11+
/// Benchmark splitting by line count
12+
#[divan::bench]
13+
fn split_lines(bencher: Bencher) {
14+
let data = text_data::generate_by_lines(100_000, 80);
15+
let file_path = setup_test_file(&data);
16+
17+
bencher
18+
.with_inputs(|| {
19+
let output_dir = TempDir::new().unwrap();
20+
let prefix = output_dir.path().join("x");
21+
(output_dir, prefix.to_str().unwrap().to_string())
22+
})
23+
.bench_values(|(output_dir, prefix)| {
24+
black_box(run_util_function(
25+
uumain,
26+
&["-l", "1000", file_path.to_str().unwrap(), &prefix],
27+
));
28+
drop(output_dir);
29+
});
30+
}
31+
32+
/// Benchmark splitting by byte size
33+
#[divan::bench]
34+
fn split_bytes(bencher: Bencher) {
35+
let data = text_data::generate_by_size(10, 80);
36+
let file_path = setup_test_file(&data);
37+
38+
bencher
39+
.with_inputs(|| {
40+
let output_dir = TempDir::new().unwrap();
41+
let prefix = output_dir.path().join("x");
42+
(output_dir, prefix.to_str().unwrap().to_string())
43+
})
44+
.bench_values(|(output_dir, prefix)| {
45+
black_box(run_util_function(
46+
uumain,
47+
&["-b", "100K", file_path.to_str().unwrap(), &prefix],
48+
));
49+
drop(output_dir);
50+
});
51+
}
52+
53+
/// Benchmark splitting by number of chunks
54+
#[divan::bench]
55+
fn split_number_chunks(bencher: Bencher) {
56+
let data = text_data::generate_by_lines(100_000, 80);
57+
let file_path = setup_test_file(&data);
58+
59+
bencher
60+
.with_inputs(|| {
61+
let output_dir = TempDir::new().unwrap();
62+
let prefix = output_dir.path().join("x");
63+
(output_dir, prefix.to_str().unwrap().to_string())
64+
})
65+
.bench_values(|(output_dir, prefix)| {
66+
black_box(run_util_function(
67+
uumain,
68+
&["-n", "10", file_path.to_str().unwrap(), &prefix],
69+
));
70+
drop(output_dir);
71+
});
72+
}
73+
74+
/// Benchmark splitting with numeric suffix
75+
#[divan::bench]
76+
fn split_numeric_suffix(bencher: Bencher) {
77+
let data = text_data::generate_by_lines(100_000, 80);
78+
let file_path = setup_test_file(&data);
79+
80+
bencher
81+
.with_inputs(|| {
82+
let output_dir = TempDir::new().unwrap();
83+
let prefix = output_dir.path().join("x");
84+
(output_dir, prefix.to_str().unwrap().to_string())
85+
})
86+
.bench_values(|(output_dir, prefix)| {
87+
black_box(run_util_function(
88+
uumain,
89+
&["-d", "-l", "500", file_path.to_str().unwrap(), &prefix],
90+
));
91+
drop(output_dir);
92+
});
93+
}
94+
95+
fn main() {
96+
divan::main();
97+
}

0 commit comments

Comments
 (0)