| 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 std::fmt::Write; |
| 8 |
use tempfile::TempDir; |
| 9 |
use uu_expand::uumain; |
| 10 |
use uucore::benchmark::{create_test_file, get_bench_args}; |
| 11 |
|
| 12 |
/// Benchmark expanding tabs on files with many short lines |
| 13 |
#[divan::bench(args = [100_000])] |
| 14 |
fn expand_many_lines(bencher: Bencher, num_lines: usize) { |
| 15 |
let data = (0..num_lines).fold(String::new(), |mut acc, i| { |
| 16 |
writeln!(&mut acc, "line{i}\tvalue{}\tdata{}", i * 2, i * 3).unwrap(); |
| 17 |
acc |
| 18 |
}); |
| 19 |
let temp_dir = TempDir::new().unwrap(); |
| 20 |
let file_path = create_test_file(data.as_ref(), temp_dir.path()); |
| 21 |
|
| 22 |
bencher |
| 23 |
.with_inputs(|| get_bench_args(&[&file_path]).into_iter()) |
| 24 |
.bench_values(|args| black_box(uumain(args))); |
| 25 |
} |
| 26 |
|
| 27 |
/// Benchmark expanding tabs with custom tab stops |
| 28 |
#[divan::bench(args = [50_000])] |
| 29 |
fn expand_custom_tabstops(bencher: Bencher, num_lines: usize) { |
| 30 |
let data = (0..num_lines).fold(String::new(), |mut acc, i| { |
| 31 |
writeln!(&mut acc, "a\tb\tc\td\te{i}").unwrap(); |
| 32 |
acc |
| 33 |
}); |
| 34 |
let temp_dir = TempDir::new().unwrap(); |
| 35 |
let file_path = create_test_file(data.as_ref(), temp_dir.path()); |
| 36 |
|
| 37 |
bencher |
| 38 |
.with_inputs(|| get_bench_args(&[&"--tabs=4,8,12", &file_path]).into_iter()) |
| 39 |
.bench_values(|args| black_box(uumain(args))); |
| 40 |
} |
| 41 |
|
| 42 |
fn main() { |
| 43 |
divan::main(); |
| 44 |
} |