| 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_shuf::uumain; |
| 8 |
use uucore::benchmark::{get_bench_args, setup_test_file, text_data}; |
| 9 |
|
| 10 |
/// Benchmark shuffling lines from a file |
| 11 |
/// Tests the default mode with a large number of lines |
| 12 |
#[divan::bench(args = [100_000])] |
| 13 |
fn shuf_lines(bencher: Bencher, num_lines: usize) { |
| 14 |
let data = text_data::generate_by_lines(num_lines, 80); |
| 15 |
let file_path = setup_test_file(&data); |
| 16 |
|
| 17 |
bencher |
| 18 |
.with_inputs(|| get_bench_args(&[&file_path]).into_iter()) |
| 19 |
.bench_values(|args| black_box(uumain(args))); |
| 20 |
} |
| 21 |
|
| 22 |
/// Benchmark shuffling a numeric range with -i |
| 23 |
/// Tests the input-range mode which uses a different algorithm |
| 24 |
#[divan::bench(args = [1_000_000])] |
| 25 |
fn shuf_input_range(bencher: Bencher, range_size: usize) { |
| 26 |
let range_arg = format!("1-{range_size}"); |
| 27 |
|
| 28 |
bencher |
| 29 |
.with_inputs(|| get_bench_args(&[&"-i", &range_arg]).into_iter()) |
| 30 |
.bench_values(|args| black_box(uumain(args))); |
| 31 |
} |
| 32 |
|
| 33 |
/// Benchmark shuffling with repeat (sampling with replacement) |
| 34 |
/// Tests the -r flag combined with -n to output a specific count |
| 35 |
#[divan::bench(args = [50_000])] |
| 36 |
fn shuf_repeat_sampling(bencher: Bencher, num_lines: usize) { |
| 37 |
let data = text_data::generate_by_lines(10_000, 80); |
| 38 |
let file_path = setup_test_file(&data); |
| 39 |
let count = format!("{num_lines}"); |
| 40 |
|
| 41 |
bencher |
| 42 |
.with_inputs(|| get_bench_args(&[&"-r", &"-n", &count, &file_path]).into_iter()) |
| 43 |
.bench_values(|args| black_box(uumain(args))); |
| 44 |
} |
| 45 |
|
| 46 |
fn main() { |
| 47 |
divan::main(); |
| 48 |
} |