Speeding up redirection to NUL?

May 20, 2008
10,634
81
Syracuse, NY, USA
Well, I can control what my app does, but not what hundreds of others do ... others which I might want to redirect to NUL. Can you give me some idea why these times are so different and what my app is supposed to do to make redirection to NUL faster? Below, wc is an external and lc is a plugin version of "wc -l".
Code:
l:\projects\perms\release> timer & perms abcdefghij | wc -l & timer
Timer 1 on: 11:42:42
3628800
Timer 1 off: 11:42:43  Elapsed: 0:00:01.50

l:\projects\perms\release> timer & perms abcdefghij > nul & timer
Timer 1 on: 11:42:49
Timer 1 off: 11:43:15  Elapsed: 0:00:26.24

l:\projects\perms\release> timer & perms abcdefghij | lc & timer
Timer 1 on: 11:45:13
3628800
Timer 1 off: 11:45:15  Elapsed: 0:00:01.44
 
May 20, 2008
10,634
81
Syracuse, NY, USA
I must not know what you mean. My app uses a single printf() statement. If I change stdout to unbuffered, like this,
Code:
setvbuf(stdout, NULL, _IONBF, 0);
then the (already outrageous) time of 26 seconds jumps to over 10 minutes!
 
May 20, 2008
10,634
81
Syracuse, NY, USA
OTOH, if I give stdout a large buffer, like this,
Code:
setvbuf(stdout, NULL, _IOFBF, 65536);
I cut the 26 seconds to 1.4 seconds (about where it should be). If I also
Code:
_setmode(_fileno(stdout), _O_BINARY); // also change "\n" to "\r\n"
I can get it down to 1.2 seconds.