Chargen patch
Paul Fox
pgf at brightstareng.com
Tue Nov 7 07:41:23 PST 2006
> > > + while (nr--)
> > > + {
> > > + bb_printf ("%c", ch);
> > > + }
> >
> >
> > uh, no. i don't think so.
> >
>
> Out of curiosity - what is wrong with the while() loop above?
> Or is it the bb_printf() usage wrong?
printf() is a very high level, very expensive call, intended to do
complex formatting of data. your chargen app doesn't need any of
its features, so why use it? you were causing your program to waste
cycles. instead, you could have written:
while (nr--)
putchar(ch);
but what's really wasteful is your while loop. it's calling a lot
of code for _every_ character. you're calling printf (or, in my
replacement, putchar()) over 16000 times! consider something like this,
instead:
unsigned char buf[1024];
memset(buf, ch, sizeof(buf));
while (nr >= sizeof(buf)) {
write(1, buf, sizeof(buf));
nr -= sizeof(buf);
}
if (nr) write(1, buf, nr);
=---------------------
paul fox, pgf at brightstareng.com
More information about the busybox
mailing list