diff --git a/src/uu/sum/BENCHMARKING.md b/src/uu/sum/BENCHMARKING.md index 30cda74710b..17e04ee43cc 100644 --- a/src/uu/sum/BENCHMARKING.md +++ b/src/uu/sum/BENCHMARKING.md @@ -13,11 +13,11 @@ cargo build --release --package uu_sum and then you can time how it long it takes to checksum the file by running ```shell -time ./target/release/sum wikidatawiki-20211001-pages-logging.xml +time ./target/release/sum wikidatawiki-20251220-pages-logging.xml ``` For more systematic measurements that include warm-ups, repetitions and comparisons, [Hyperfine](https://github.com/sharkdp/hyperfine) can be helpful. For example, to compare this implementation to the one provided by your distribution run ```shell -hyperfine "./target/release/sum wikidatawiki-20211001-pages-logging.xml" "sum wikidatawiki-20211001-pages-logging.xml" +hyperfine "./target/release/sum wikidatawiki-20251220-pages-logging.xml" "sum wikidatawiki-20251220-pages-logging.xml" ``` diff --git a/src/uu/sum/src/sum.rs b/src/uu/sum/src/sum.rs index 6ff80efba5a..d16718612c9 100644 --- a/src/uu/sum/src/sum.rs +++ b/src/uu/sum/src/sum.rs @@ -16,8 +16,11 @@ use uucore::translate; use uucore::{format_usage, show}; +// Fixed to 8 KiB (equivalent to `std::sys::io::DEFAULT_BUF_SIZE` on most targets) +const DEFAULT_BUF_SIZE: usize = 8 * 1024; + fn bsd_sum(mut reader: impl Read) -> std::io::Result<(usize, u16)> { - let mut buf = [0; 4096]; + let mut buf = [0; DEFAULT_BUF_SIZE]; let mut bytes_read = 0; let mut checksum: u16 = 0; loop { @@ -41,7 +44,7 @@ fn bsd_sum(mut reader: impl Read) -> std::io::Result<(usize, u16)> { } fn sysv_sum(mut reader: impl Read) -> std::io::Result<(usize, u16)> { - let mut buf = [0; 4096]; + let mut buf = [0; DEFAULT_BUF_SIZE]; let mut bytes_read = 0; let mut ret = 0u32;