Skip to content

Commit

Permalink
Add comment regarding block sizes.
Browse files Browse the repository at this point in the history
  • Loading branch information
resistor committed Jul 27, 2022
1 parent 0ec54b2 commit 168c487
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
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
$ /usr/bin/time ./target/release/sum wikidatawiki-20211001-pages-logging.xml
$ time ./target/release/sum wikidatawiki-20211001-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" "/usr/bin/sum wikidatawiki-20211001-pages-logging.xml"
$ hyperfine "./target/release/sum wikidatawiki-20211001-pages-logging.xml" "sum wikidatawiki-20211001-pages-logging.xml"
```
2 changes: 2 additions & 0 deletions src/uu/sum/src/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ fn bsd_sum(mut reader: Box<dyn Read>) -> (usize, u16) {
}
}

// Report blocks read in terms of 1024-byte blocks.
let blocks_read = div_ceil(bytes_read, 1024);
(blocks_read, checksum)
}
Expand All @@ -69,6 +70,7 @@ fn sysv_sum(mut reader: Box<dyn Read>) -> (usize, u16) {
ret = (ret & 0xffff) + (ret >> 16);
ret = (ret & 0xffff) + (ret >> 16);

// Report blocks read in terms of 512-byte blocks.
let blocks_read = div_ceil(bytes_read, 512);
(blocks_read, ret as u16)
}
Expand Down

0 comments on commit 168c487

Please sign in to comment.