From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH 2/3] more: make output redirection more efficient
Date: Sun, 4 Aug 2013 00:15:20 +0100 [thread overview]
Message-ID: <1375571721-30008-2-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1375571721-30008-1-git-send-email-kerolasa@iki.fi>
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@iki.fi>
---
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
next prev parent reply other threads:[~2013-08-03 23:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-03 23:15 [PATCH 1/3] column: use variable lenght printf field width to wprint blanks Sami Kerola
2013-08-03 23:15 ` Sami Kerola [this message]
2013-08-05 8:48 ` [PATCH 2/3] more: make output redirection more efficient Karel Zak
2013-08-03 23:15 ` [PATCH 3/3] cal: set statically defined data read-only Sami Kerola
2013-08-05 8:49 ` Karel Zak
2013-08-05 8:48 ` [PATCH 1/3] column: use variable lenght printf field width to wprint blanks Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1375571721-30008-2-git-send-email-kerolasa@iki.fi \
--to=kerolasa@iki.fi \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox