Debian Codegraph @

src/uu/nl/benches/nl_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 uu_nl::uumain;
8 use uucore::benchmark::{create_test_file, run_util_function, text_data};
9
10 /// Benchmark numbering many lines (default mode - most common use case)
11 #[divan::bench(args = [100_000])]
12 fn nl_many_lines(bencher: Bencher, num_lines: usize) {
13 let temp_dir = tempfile::tempdir().unwrap();
14 let data = text_data::generate_by_lines(num_lines, 80);
15 let file_path = create_test_file(&data, temp_dir.path());
16 let file_path_str = file_path.to_str().unwrap();
17
18 bencher.bench(|| {
19 black_box(run_util_function(uumain, &[file_path_str]));
20 });
21 }
22
23 /// Benchmark large file with -ba option (number all lines - most common argument)
24 #[divan::bench(args = [10])]
25 fn nl_large_file(bencher: Bencher, size_mb: usize) {
26 let temp_dir = tempfile::tempdir().unwrap();
27 let data = text_data::generate_by_size(size_mb, 80);
28 let file_path = create_test_file(&data, temp_dir.path());
29 let file_path_str = file_path.to_str().unwrap();
30
31 bencher.bench(|| {
32 black_box(run_util_function(uumain, &["-ba", file_path_str]));
33 });
34 }
35
36 fn main() {
37 divan::main();
38 }