No, he's not. *Sometimes* it is faster to use write() instead
of fwrite(). Other times it's not. Here's the result of a
quick test:
$ time ./a.out 500000 > /dev/null # Use putc
real 0m0.015s
user 0m0.012s
sys 0m0.002s
$ time ./a.out 500000 USE_WRITE > /dev/null
real 0m0.891s
user 0m0.329s
sys 0m0.558s
(The code used to generate this is below.)
The interpretation of this is simple: using putc
improves performance precisely because of the buffering.
There is no doubt that using write() will often improve
the performance, but NOT if you are making lots of
small writes. When in doubt (and if there is an
actual, observed performance problem) you must
profile the process to determine the bottleneck.
If the problem is IO performance due to fwrite(),
it might be worthwhile to use write() instead.
Might be. Repeated again for emphasis. *Might* be.
If you invest the time re-writing the code to
use write(), you must verify that the performance
gain (or loss) is what you want. You may find
that you have improved throughput by .00001%. Or
maybe you have reduced it by 20%. There are many
managers who will take the 20% performance hit and
call it an improvement and give you a bonus. Take
the money, but find a more competent manager.
Here's the code used to generate the above timings:
/* Unix specific code */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int
use_write( int c )
{
int status = c;
char C = c;
if( write( STDOUT_FILENO, &C, 1 ) != 1 )
status = EOF;
return status;
}
int
use_putc( int c )
{
return putchar( c );
}
int
main( int argc, char **argv )
{
unsigned count;
int (*f)(int);
f = ( argc > 2 ) ? use_write : use_putc;
count = ( argc > 1 ) ? strtoul( argv[ 1 ], NULL, 10 ) : BUFSIZ;
for( ; count; count-- )
if( f( 'y' ) != 'y' )
break;;
return count ? EXIT_FAILURE : EXIT_SUCCESS;
}