Skip to content

Commit

Permalink
Speed up sum by using reasonable read buffer sizes.
Browse files Browse the repository at this point in the history
Use a 4K read buffer for each of the checksum functions, which seems
reasonable. This improves the performance of BSD checksums on
odyssey1024.txt from 399ms to 325ms on my laptop, and of SysV
checksums from 242ms to 67ms.
  • Loading branch information
resistor committed Jul 24, 2022
1 parent ec9130a commit 9e1d918
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/uu/sum/src/sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static SUMMARY: &str = "Checksum and count the blocks in a file.\n\
With no FILE, or when FILE is -, read standard input.";

fn bsd_sum(mut reader: Box<dyn Read>) -> (usize, u16) {
let mut buf = [0; 1024];
let mut buf = [0; 4096];
let mut blocks_read = 0;
let mut checksum: u16 = 0;
loop {
Expand All @@ -44,7 +44,7 @@ fn bsd_sum(mut reader: Box<dyn Read>) -> (usize, u16) {
}

fn sysv_sum(mut reader: Box<dyn Read>) -> (usize, u16) {
let mut buf = [0; 512];
let mut buf = [0; 4096];
let mut blocks_read = 0;
let mut ret = 0u32;

Expand Down

0 comments on commit 9e1d918

Please sign in to comment.