[PATCH 2/3] more: make output redirection more efficient

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Especially with large inputs the change improves performance
considerably.

old> time more /boot/vmlinuz >/dev/null
real    0m0.224s

new> more /boot/vmlinuz >/dev/null
real    0m0.009s

Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 text-utils/more.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/text-utils/more.c b/text-utils/more.c
index ac35acc..598e048 100644
--- a/text-utils/more.c
+++ b/text-utils/more.c
@@ -780,10 +780,11 @@ void __attribute__((__noreturn__)) end_it(int dummy __attribute__((__unused__)))
 
 void copy_file(register FILE *f)
 {
-	register int c;
+	char buf[BUFSIZ];
+	size_t sz;
 
-	while ((c = getc(f)) != EOF)
-		putchar(c);
+	while ((sz = fread(&buf, sizeof(char), sizeof(buf), f)) > 0)
+		fwrite(&buf, sizeof(char), sz, stdout);
 }
 
 #define ringbell()	putcerr('\007')
-- 
1.8.3.4

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux