Results 1 to 4 of 4

Thread: Slow output to nul:

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Expert
    Matt Mahoney's Avatar
    Join Date
    May 2008
    Location
    Melbourne, Florida, USA
    Posts
    3,257
    Thanks
    307
    Thanked 797 Times in 489 Posts

    Question Slow output to nul:

    I found some strange behavior when testing output speed. The following program outputs the letter A 500,000 times to a file named as an argument, or to stdout by default.

    Code:
    // t.cpp
    #include <stdio.h>
    int main(int argc, char** argv) {
      FILE* out=stdout;
      if (argc==2) out=fopen(argv[1], "wb");
      for (int i=0; i<500000; ++i) putc('A', out);
      return 0;
    }
    The following commands all run in less than 0.05 seconds:

    Code:
    t x  (write to file x)
    t nul: (discard output)
    t > x (redirect stdout to file x)
    copy x x1
    copy x nul:
    type x > x1
    type x > nul:
    But the following takes 14 seconds.
    Code:
    t > nul:
    I get the same behavior whether I compile with g++ v4.6.1 (g++ -O3 -fomit-frame-pointer, also g++ with no optimization) or Microsoft 16.00.30319.01 (cl /O2 or cl). I'm testing under Vista SP2 32 bit on a 2.0 GHz T3200. I tried varying the output size, and time is proportional. Anyone else see this behavior?

    Edit: same problem in Windows 7 Enterprise 32 bit, Intel Core i7 M620, 2.67 GHz, except it only takes 7 seconds because it's a faster machine.

    Edit: the problem does NOT occur in Windows XP home edition (2002 SP3) 32 bit on a 2.2 GHz Athlon-64 3500+.
    Last edited by Matt Mahoney; 30th December 2011 at 19:46.

Similar Threads

  1. Rangecoding with restricted output alphabet
    By Shelwien in forum Data Compression
    Replies: 0
    Last Post: 17th August 2010, 18:38
  2. Slow Visual 2010
    By Cyan in forum The Off-Topic Lounge
    Replies: 23
    Last Post: 24th May 2010, 02:03
  3. Fast arithcoder for compression of LZ77 output
    By Bulat Ziganshin in forum Forum Archive
    Replies: 13
    Last Post: 15th April 2007, 17:40

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •