mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
Merge pull request #9320 from sylvestre/shuf-bench
shuf: add benchmarks
This commit is contained in:
@@ -37,6 +37,7 @@ jobs:
|
||||
- { package: uu_numfmt }
|
||||
- { package: uu_rm }
|
||||
- { package: uu_seq }
|
||||
- { package: uu_shuf }
|
||||
- { package: uu_sort }
|
||||
- { package: uu_split }
|
||||
- { package: uu_tsort }
|
||||
|
||||
Generated
+2
@@ -3812,9 +3812,11 @@ name = "uu_shuf"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"codspeed-divan-compat",
|
||||
"fluent",
|
||||
"rand 0.9.2",
|
||||
"rand_core 0.9.3",
|
||||
"tempfile",
|
||||
"uucore",
|
||||
]
|
||||
|
||||
|
||||
@@ -27,3 +27,12 @@ fluent = { workspace = true }
|
||||
[[bin]]
|
||||
name = "shuf"
|
||||
path = "src/main.rs"
|
||||
|
||||
[[bench]]
|
||||
name = "shuf_bench"
|
||||
harness = false
|
||||
|
||||
[dev-dependencies]
|
||||
divan = { workspace = true }
|
||||
tempfile = { workspace = true }
|
||||
uucore = { workspace = true, features = ["benchmark"] }
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
// This file is part of the uutils coreutils package.
|
||||
//
|
||||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
|
||||
use divan::{Bencher, black_box};
|
||||
use uu_shuf::uumain;
|
||||
use uucore::benchmark::{run_util_function, setup_test_file, text_data};
|
||||
|
||||
/// Benchmark shuffling lines from a file
|
||||
/// Tests the default mode with a large number of lines
|
||||
#[divan::bench(args = [100_000])]
|
||||
fn shuf_lines(bencher: Bencher, num_lines: usize) {
|
||||
let data = text_data::generate_by_lines(num_lines, 80);
|
||||
let file_path = setup_test_file(&data);
|
||||
let file_path_str = file_path.to_str().unwrap();
|
||||
|
||||
bencher.bench(|| {
|
||||
black_box(run_util_function(uumain, &[file_path_str]));
|
||||
});
|
||||
}
|
||||
|
||||
/// Benchmark shuffling a numeric range with -i
|
||||
/// Tests the input-range mode which uses a different algorithm
|
||||
#[divan::bench(args = [1_000_000])]
|
||||
fn shuf_input_range(bencher: Bencher, range_size: usize) {
|
||||
let range_arg = format!("1-{range_size}");
|
||||
|
||||
bencher.bench(|| {
|
||||
black_box(run_util_function(uumain, &["-i", &range_arg]));
|
||||
});
|
||||
}
|
||||
|
||||
/// Benchmark shuffling with repeat (sampling with replacement)
|
||||
/// Tests the -r flag combined with -n to output a specific count
|
||||
#[divan::bench(args = [50_000])]
|
||||
fn shuf_repeat_sampling(bencher: Bencher, num_lines: usize) {
|
||||
let data = text_data::generate_by_lines(10_000, 80);
|
||||
let file_path = setup_test_file(&data);
|
||||
let file_path_str = file_path.to_str().unwrap();
|
||||
let count = format!("{num_lines}");
|
||||
|
||||
bencher.bench(|| {
|
||||
black_box(run_util_function(
|
||||
uumain,
|
||||
&["-r", "-n", &count, file_path_str],
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
fn main() {
|
||||
divan::main();
|
||||
}
|
||||
Reference in New Issue
Block a user