Skip to content

Commit 3d8002e

Browse files
authored
Merge branch 'main' into patch-4
2 parents 8941074 + b0f41e7 commit 3d8002e

9 files changed

Lines changed: 86 additions & 25 deletions

File tree

.github/workflows/benchmarks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
- { package: uu_numfmt }
3838
- { package: uu_rm }
3939
- { package: uu_seq }
40+
- { package: uu_shuf }
4041
- { package: uu_sort }
4142
- { package: uu_split }
4243
- { package: uu_tsort }

Cargo.lock

Lines changed: 9 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,6 @@ notify = { version = "=8.2.0", features = ["macos_kqueue"] }
349349
num-bigint = "0.4.4"
350350
num-prime = "0.4.4"
351351
num-traits = "0.2.19"
352-
number_prefix = "0.4"
353352
onig = { version = "~6.5.1", default-features = false }
354353
parse_datetime = "0.13.0"
355354
phf = "0.13.1"
@@ -373,6 +372,7 @@ textwrap = { version = "0.16.1", features = ["terminal_size"] }
373372
thiserror = "2.0.3"
374373
time = { version = "0.3.36" }
375374
unicode-width = "0.2.0"
375+
unit-prefix = "0.5"
376376
utmp-classic = "0.1.6"
377377
uutils_term_grid = "0.7"
378378
walkdir = "2.5"

fuzz/Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/shuf/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,12 @@ fluent = { workspace = true }
2727
[[bin]]
2828
name = "shuf"
2929
path = "src/main.rs"
30+
31+
[[bench]]
32+
name = "shuf_bench"
33+
harness = false
34+
35+
[dev-dependencies]
36+
divan = { workspace = true }
37+
tempfile = { workspace = true }
38+
uucore = { workspace = true, features = ["benchmark"] }

src/uu/shuf/benches/shuf_bench.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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::{run_util_function, 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+
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 shuffling a numeric range with -i
24+
/// Tests the input-range mode which uses a different algorithm
25+
#[divan::bench(args = [1_000_000])]
26+
fn shuf_input_range(bencher: Bencher, range_size: usize) {
27+
let range_arg = format!("1-{range_size}");
28+
29+
bencher.bench(|| {
30+
black_box(run_util_function(uumain, &["-i", &range_arg]));
31+
});
32+
}
33+
34+
/// Benchmark shuffling with repeat (sampling with replacement)
35+
/// Tests the -r flag combined with -n to output a specific count
36+
#[divan::bench(args = [50_000])]
37+
fn shuf_repeat_sampling(bencher: Bencher, num_lines: usize) {
38+
let data = text_data::generate_by_lines(10_000, 80);
39+
let file_path = setup_test_file(&data);
40+
let file_path_str = file_path.to_str().unwrap();
41+
let count = format!("{num_lines}");
42+
43+
bencher.bench(|| {
44+
black_box(run_util_function(
45+
uumain,
46+
&["-r", "-n", &count, file_path_str],
47+
));
48+
});
49+
}
50+
51+
fn main() {
52+
divan::main();
53+
}

src/uucore/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ bstr = { workspace = true }
2626
chrono = { workspace = true, optional = true }
2727
clap = { workspace = true }
2828
uucore_procs = { workspace = true }
29-
number_prefix = { workspace = true }
29+
unit-prefix = { workspace = true }
3030
phf = { workspace = true }
3131
dns-lookup = { workspace = true, optional = true }
3232
dunce = { version = "1.0.4", optional = true }

src/uucore/src/lib/features/format/human.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//!
1010
//! Format sizes like gnulibs human_readable() would
1111
12-
use number_prefix::NumberPrefix;
12+
use unit_prefix::NumberPrefix;
1313

1414
#[derive(Copy, Clone, PartialEq)]
1515
pub enum SizeFormat {

util/build-gnu.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,17 @@ test -f "${UU_BUILD_DIR}/[" || (cd ${UU_BUILD_DIR} && ln -s "test" "[")
121121

122122
cd "${path_GNU}" && echo "[ pwd:'${PWD}' ]"
123123

124+
# Always update the PATH to test the uutils coreutils instead of the GNU coreutils
125+
# This ensures the correct path is used even if the repository was moved or rebuilt in a different location
126+
sed -i "s/^[[:blank:]]*PATH=.*/ PATH='${UU_BUILD_DIR//\//\\/}\$(PATH_SEPARATOR)'\"\$\$PATH\" \\\/" tests/local.mk
127+
124128
if test -f gnu-built; then
125129
echo "GNU build already found. Skip"
126130
echo "'rm -f $(pwd)/gnu-built' to force the build"
127131
echo "Note: the customization of the tests will still happen"
128132
else
129133
# Disable useless checks
130134
sed -i 's|check-texinfo: $(syntax_checks)|check-texinfo:|' doc/local.mk
131-
# Change the PATH to test the uutils coreutils instead of the GNU coreutils
132-
sed -i "s/^[[:blank:]]*PATH=.*/ PATH='${UU_BUILD_DIR//\//\\/}\$(PATH_SEPARATOR)'\"\$\$PATH\" \\\/" tests/local.mk
133135
./bootstrap --skip-po
134136
./configure --quiet --disable-gcc-warnings --disable-nls --disable-dependency-tracking --disable-bold-man-page-references \
135137
"$([ "${SELINUX_ENABLED}" = 1 ] && echo --with-selinux || echo --without-selinux)"

0 commit comments

Comments
 (0)