From 9e1d9186484508c48b7629c777aabcf6afedf607 Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Sat, 23 Jul 2022 22:05:40 -0700 Subject: [PATCH] Speed up sum by using reasonable read buffer sizes. 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. --- src/uu/sum/src/sum.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uu/sum/src/sum.rs b/src/uu/sum/src/sum.rs index 9280fcf813f..ebafe3c67b2 100644 --- a/src/uu/sum/src/sum.rs +++ b/src/uu/sum/src/sum.rs @@ -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) -> (usize, u16) { - let mut buf = [0; 1024]; + let mut buf = [0; 4096]; let mut blocks_read = 0; let mut checksum: u16 = 0; loop { @@ -44,7 +44,7 @@ fn bsd_sum(mut reader: Box) -> (usize, u16) { } fn sysv_sum(mut reader: Box) -> (usize, u16) { - let mut buf = [0; 512]; + let mut buf = [0; 4096]; let mut blocks_read = 0; let mut ret = 0u32;