printf("%s", s) considered slow

Steve Summit scs at athena.mit.edu
Fri May 4 11:05:38 AEST 1990


In article <26387BCF.390 at tct.uucp> chip at tct.uucp (Chip Salzenberg) writes:
>Aargh!  Why do people use 'printf("%s", s)' when 'fputs(s, stdout)' is
>faster on every C implementation known to humankind?

I always use printf.  I even use printf("\n") when putchar('\n')
would "obviously" be better.  The reason is the consistency
factor several people have already mentioned, but it's more than
just abstract warm fuzzies.  Many times I have been extremely
glad to be able to do global substitutions of "printf(" with
"fprintf(fd, " or "printf" with "output" or something similar,
and know that I've gotten everything without having to go back
and take care of puts's or putchar's by hand.

Even in a critical section where efficiency might matter, the
underlying physical I/O overhead often swamps any extra CPU time
that a "less efficient" path through stdio might introduce.

                                            Steve Summit
                                            scs at adam.mit.edu



More information about the Comp.lang.c mailing list