Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/uu/sum/BENCHMARKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
```
7 changes: 5 additions & 2 deletions src/uu/sum/src/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;

Expand Down
Loading