* [PATCH] ul: enhance command performance
@ 2013-06-30 8:44 Sami Kerola
2013-07-01 12:05 ` Karel Zak
0 siblings, 1 reply; 2+ messages in thread
From: Sami Kerola @ 2013-06-30 8:44 UTC (permalink / raw)
To: util-linux; +Cc: kerolasa
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ul: enhance command performance
2013-06-30 8:44 [PATCH] ul: enhance command performance Sami Kerola
@ 2013-07-01 12:05 ` Karel Zak
0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2013-07-01 12:05 UTC (permalink / raw)
To: Sami Kerola; +Cc: util-linux
On Sun, Jun 30, 2013 at 09:44:00AM +0100, Sami Kerola wrote:
> 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
Good catch :-)
> @@ -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));
> }
>
else
> /* assumes NORMAL == 0 */
> - memset(obuf, 0, sizeof(struct CHAR) * obuflen);
> + memset(obuf, 0, sizeof(struct CHAR) * col);
I think 'maxcol' rather than col is more precise solution ;-)
Applied, thanks.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-07-01 12:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-30 8:44 [PATCH] ul: enhance command performance Sami Kerola
2013-07-01 12:05 ` Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox