From ec63a44bc44abbc822d8117f4f90a107fe122dc0 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Tue, 19 May 2026 20:05:06 +0100 Subject: [PATCH] feat(sum): use larger buffer in bsd_sum and sysv_sum --- src/uu/sum/BENCHMARKING.md | 4 ++-- src/uu/sum/src/sum.rs | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) 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;