From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH] ul: enhance command performance
Date: Sun, 30 Jun 2013 09:44:00 +0100 [thread overview]
Message-ID: <1372581840-18966-1-git-send-email-kerolasa@iki.fi> (raw)
Avoid reseting, time after time, the memory which was not used. Effect
of the change is below in before and after timings.
$ time ./ul </etc/services >/dev/null
real 0m0.320s
user 0m0.307s
sys 0m0.010s
$ time ./ul </etc/services >/dev/null
real 0m0.068s
user 0m0.050s
sys 0m0.017s
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
text-utils/ul.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/text-utils/ul.c b/text-utils/ul.c
index 5710a55..572f1b8 100644
--- a/text-utils/ul.c
+++ b/text-utils/ul.c
@@ -491,11 +491,11 @@ static void initbuf(void)
if (obuf == NULL) {
/* First time. */
obuflen = BUFSIZ;
- obuf = xmalloc(sizeof(struct CHAR) * obuflen);
+ obuf = xcalloc(obuflen, sizeof(struct CHAR));
}
/* assumes NORMAL == 0 */
- memset(obuf, 0, sizeof(struct CHAR) * obuflen);
+ memset(obuf, 0, sizeof(struct CHAR) * col);
setcol(0);
maxcol = 0;
mode &= ALTSET;
--
1.8.3.1
next reply other threads:[~2013-06-30 8:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-30 8:44 Sami Kerola [this message]
2013-07-01 12:05 ` [PATCH] ul: enhance command performance 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=1372581840-18966-1-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