why is fprintf(stderr,) slow?

Chris Torek chris at umcp-cs.UUCP
Wed Aug 20 14:59:20 AEST 1986


In article <19300053 at uiucdcsb> wsmith at uiucdcsb.CS.UIUC.EDU writes:
>I was doing some performance testing on a program and as part of it
>I was doing about 500 fprintf(stderr, "blah...\n");

>The program was taking 35 or 40 seconds of system time which was pretty
>high.  I then commented out the fprintf's and the program took 17 or 18
>system time seconds (it was doing a lot of disk accesses).

stderr is `traditionally' unbuffered.  That means that fprintf()s
to it write one character at a time.  This is indeed quite expensive.
The 4.3BSD fprintf---or more precisely, _doprnt---temporarily turns
on block buffering for some (but not all) operations.  I have, in
the past, added a `setbuf' or `setlinebuf' call to force buffering
on stderr.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.unix mailing list