Debian Codegraph @

src/uu/split/benches/split_bench.rs

raw
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::{get_bench_args, 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 let args = get_bench_args(&[&"-l", &"1000", &file_path, &prefix]).into_iter();
22 (output_dir, args)
23 })
24 .bench_values(|(output_dir, args)| {
25 black_box(uumain(args));
26 drop(output_dir);
27 });
28 }
29
30 /// Benchmark splitting by byte size
31 #[divan::bench]
32 fn split_bytes(bencher: Bencher) {
33 let data = text_data::generate_by_size(10, 80);
34 let file_path = setup_test_file(&data);
35
36 bencher
37 .with_inputs(|| {
38 let output_dir = TempDir::new().unwrap();
39 let prefix = output_dir.path().join("x");
40 let args = get_bench_args(&[&"-b", &"100K", &file_path, &prefix]).into_iter();
41 (output_dir, args)
42 })
43 .bench_values(|(output_dir, args)| {
44 black_box(uumain(args));
45 drop(output_dir);
46 });
47 }
48
49 /// Benchmark splitting by number of chunks
50 #[divan::bench]
51 fn split_number_chunks(bencher: Bencher) {
52 let data = text_data::generate_by_lines(100_000, 80);
53 let file_path = setup_test_file(&data);
54
55 bencher
56 .with_inputs(|| {
57 let output_dir = TempDir::new().unwrap();
58 let prefix = output_dir.path().join("x");
59 let args = get_bench_args(&[&"-n", &"10", &file_path, &prefix]).into_iter();
60 (output_dir, args)
61 })
62 .bench_values(|(output_dir, args)| {
63 black_box(uumain(args));
64 drop(output_dir);
65 });
66 }
67
68 /// Benchmark splitting with numeric suffix
69 #[divan::bench]
70 fn split_numeric_suffix(bencher: Bencher) {
71 let data = text_data::generate_by_lines(100_000, 80);
72 let file_path = setup_test_file(&data);
73
74 bencher
75 .with_inputs(|| {
76 let output_dir = TempDir::new().unwrap();
77 let prefix = output_dir.path().join("x");
78 let args = get_bench_args(&[&"-d", &"-l", &"500", &file_path, &prefix]).into_iter();
79 (output_dir, args)
80 })
81 .bench_values(|(output_dir, args)| {
82 black_box(uumain(args));
83 drop(output_dir);
84 });
85 }
86
87 fn main() {
88 divan::main();
89 }