cat

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jag

    cat

    I've read parts of K&R's ANSI C v2 and this is what their cat looked
    like but when I compared the speed of this code to gnu cat, it seems
    very slow. How do I optimize this for greater speeds? is there an
    alternative algorithm?

    void catfile(FILE *in, FILE *out) {
    register int num_char;

    /*Get characters*/
    while ((num_char = getc(in)) != EOF) {
    /*Print to standard output*/
    putc(num_char, out);
    }
    }

    Thanks.
  • Micah Cowan

    #2
    Re: cat

    Jag <talon.jag@gmai l.comwrites:
    I've read parts of K&R's ANSI C v2 and this is what their cat looked
    like but when I compared the speed of this code to gnu cat, it seems
    very slow. How do I optimize this for greater speeds? is there an
    alternative algorithm?
    >
    void catfile(FILE *in, FILE *out) {
    register int num_char;
    >
    /*Get characters*/
    while ((num_char = getc(in)) != EOF) {
    /*Print to standard output*/
    putc(num_char, out);
    }
    }
    This example was intended to be just that: an example. It gives a
    clear, concise method for copying in to out.

    If you look at GNU cat's source code, you'll see that it's nowhere
    near as clear and concise (this is due in no small part to the fact
    that it has to do a good deal more than the above example does,
    including some options that require a bit of processing on the input).

    POSIX systems that support the thread-safety option have to lock the
    I/O streams every time you call getc() or putc(). On such systems,
    getc_unlocked() and putc_unlocked() (POSIX options, not Standard C)
    will usually be notably faster. Some implementations also provide
    other means for using the "unlocked" versions.

    Other common techniques would be to read in larger blocks at a time,
    or perhaps to avoid the Standard C buffered I/O calls and use POSIX
    read(), write() (it's unclear to me how much better that is than to
    use setvbuf() to turn off buffering and use fwrite() and fread(),
    which is a good option if you'd like to stick to Standard C).

    Taking a look at the source code for GNU cat and other similar
    utilities like dd, for (Unix-specific) ideas on how to improve
    efficiency.

    --
    HTH,
    Micah J. Cowan
    Programmer, musician, typesetting enthusiast, gamer...

    Comment

    • CBFalconer

      #3
      Re: cat

      Jag wrote:
      >
      I've read parts of K&R's ANSI C v2 and this is what their cat
      looked like but when I compared the speed of this code to gnu
      cat, it seems very slow. How do I optimize this for greater
      speeds? is there an alternative algorithm?
      >
      void catfile(FILE *in, FILE *out) {
      register int num_char;
      >
      /*Get characters*/
      while ((num_char = getc(in)) != EOF) {
      /*Print to standard output*/
      putc(num_char, out);
      }
      }
      You may find the following faster:

      void catfile(FILE *in, FILE *out) {
      int ch;

      while (EOF != (ch = getc(in))) putc(out, ch);
      }

      If so, consider why.

      --
      [mail]: Chuck F (cbfalconer at maineline dot net)
      [page]: <http://cbfalconer.home .att.net>
      Try the download section.



      --
      Posted via a free Usenet account from http://www.teranews.com

      Comment

      • Eric Sosman

        #4
        Re: cat

        CBFalconer wrote:
        Jag wrote:
        >I've read parts of K&R's ANSI C v2 and this is what their cat
        >looked like but when I compared the speed of this code to gnu
        >cat, it seems very slow. How do I optimize this for greater
        >speeds? is there an alternative algorithm?
        >>
        >void catfile(FILE *in, FILE *out) {
        > register int num_char;
        >>
        > /*Get characters*/
        > while ((num_char = getc(in)) != EOF) {
        > /*Print to standard output*/
        > putc(num_char, out);
        > }
        >}
        >
        You may find the following faster:
        >
        void catfile(FILE *in, FILE *out) {
        int ch;
        >
        while (EOF != (ch = getc(in))) putc(out, ch);
        }
        >
        If so, consider why.
        I don't see why it would be faster. As far as I can
        tell, the only substantive change is the removal of
        `register', which is unlikely to make a difference --
        and if it does make a difference, it's likely to make
        the revised code slower, not faster.

        (Well, there's one other "speed improvement," and it
        could be a large one: Code that doesn't compile uses very
        little execution time! Have another look at the putc()
        call ...)

        --
        Eric Sosman
        esosman@ieee-dot-org.invalid

        Comment

        • Gerry Ford

          #5
          Re: cat

          Ohimigod!

          I am recently given to understand that cat means something other than
          one-half of the dead felines in arbitrary buckets.

          I sense that you drank of the forbidden K&R chapter, forbidden, not by these
          jerks but by the standard, Dan Pop, Elvis, and me.

          --
          Gerry Ford

          "Er hat sich georgiert." Der Spiegel, 2008, sich auf Chimpy Eins komma null
          beziehend.
          "Eric Sosman" <esosman@ieee-dot-org.invalidwrot e in message
          news:k8Kdnc8vbO Oj61LanZ2dnUVZ_ oOnnZ2d@comcast .com...
          CBFalconer wrote:
          >Jag wrote:
          >>I've read parts of K&R's ANSI C v2 and this is what their cat
          >>looked like but when I compared the speed of this code to gnu
          >>cat, it seems very slow. How do I optimize this for greater
          >>speeds? is there an alternative algorithm?
          >>>
          >>void catfile(FILE *in, FILE *out) {
          >> register int num_char;
          >>>
          >> /*Get characters*/
          >> while ((num_char = getc(in)) != EOF) {
          >> /*Print to standard output*/
          >> putc(num_char, out);
          >> }
          >>}
          >>
          >You may find the following faster:
          >>
          >void catfile(FILE *in, FILE *out) {
          > int ch;
          >>
          > while (EOF != (ch = getc(in))) putc(out, ch);
          >}
          >>
          >If so, consider why.
          >
          I don't see why it would be faster. As far as I can
          tell, the only substantive change is the removal of
          `register', which is unlikely to make a difference --
          and if it does make a difference, it's likely to make
          the revised code slower, not faster.
          >
          (Well, there's one other "speed improvement," and it
          could be a large one: Code that doesn't compile uses very
          little execution time! Have another look at the putc()
          call ...)
          >
          --
          Eric Sosman
          esosman@ieee-dot-org.invalid

          Comment

          • Micah Cowan

            #6
            Braces or not [Re: cat]

            Richard <devr_@gmail.co mwrites:
            And on that subject I often find
            it pays dividends in the maintenance stakes to always bracket off the
            body of conditions even if they are only one line e.g
            >
            ,----
            | while(c){
            | c=do(c);
            | }
            `----
            You state that it pays dividends, but neglect to state how/why.

            I'm guessing you mean that, if you have:

            while(c)
            c=do(c);

            And then later want to add another statement in the while's body, then
            you have to go through the tedium of adding braces first.

            If that's what you mean, then my answer is:
            - It's not appreciably harder to add braces later than it is to put
            them in in the first place.
            - In a decent editor, such as emacs or vim, it's simple to define a
            new macro to automatically add (or remove) braces for one-line
            bodies.

            --
            Micah J. Cowan
            Programmer, musician, typesetting enthusiast, gamer...

            Comment

            • Richard Heathfield

              #7
              Re: Braces or not [Re: cat]

              Micah Cowan said:

              <snip>
              I'm guessing you mean that, if you have:
              >
              while(c)
              c=do(c);
              >
              And then later want to add another statement in the while's body, then
              you have to go through the tedium of adding braces first.
              That isn't the issue. If the compound statement has two statements, you
              need the braces anyway, and it doesn't make a lot of odds whether you add
              them now or later. In fact, if that *were* the only issue, deferring them
              could save you (a miniscule amount of) work.
              If that's what you mean, then my answer is:
              - It's not appreciably harder to add braces later than it is to put
              them in in the first place.
              Agreed. BUT - it is appreciably harder to remember to add them later on
              special occasions than to put them in every time as a matter of habit.
              - In a decent editor, such as emacs or vim, it's simple to define a
              new macro to automatically add (or remove) braces for one-line
              bodies.
              That's as maybe, but it isn't the work of adding such tools - it's the work
              of remembering to use them. Unless, of course, by "automatic" you really
              do mean automatic!! :-)

              --
              Richard Heathfield <http://www.cpax.org.uk >
              Email: -http://www. +rjh@
              Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
              "Usenet is a strange place" - dmr 29 July 1999

              Comment

              • Micah Cowan

                #8
                Re: Braces or not [Re: cat]

                Richard Heathfield <rjh@see.sig.in validwrites:
                >If that's what you mean, then my answer is:
                > - It's not appreciably harder to add braces later than it is to put
                > them in in the first place.
                >
                Agreed. BUT - it is appreciably harder to remember to add them later on
                special occasions than to put them in every time as a matter of habit.
                Hm. I haven't found it to be so.

                while (c)
                c=do_it(c);
                c=do_another_th ing(c);

                looks too broken right away for me not to notice it (though, perhaps
                now that I'm doing more Python coding work these days, that may
                change?).

                I used to actually always put the braces in. I've fallen out of that
                practice, just because I find it slightly more readable without, for
                one-line bodies.

                --
                Micah J. Cowan
                Programmer, musician, typesetting enthusiast, gamer...

                Comment

                • Jag

                  #9
                  Re: cat

                  On Mar 6, 11:08 am, Micah Cowan <mi...@holliste r.bcsweb.comwro te:
                  Jag <talon....@gmai l.comwrites:
                  I've read parts of K&R's ANSI C v2 and this is what their cat looked
                  like but when I compared the speed of this code to gnu cat, it seems
                  very slow. How do I optimize this for greater speeds? is there an
                  alternative algorithm?
                  >
                  void catfile(FILE *in, FILE *out) {
                  register int num_char;
                  >
                  /*Get characters*/
                  while ((num_char = getc(in)) != EOF) {
                  /*Print to standard output*/
                  putc(num_char, out);
                  }
                  }
                  >
                  This example was intended to be just that: an example. It gives a
                  clear, concise method for copying in to out.
                  >
                  If you look at GNU cat's source code, you'll see that it's nowhere
                  near as clear and concise (this is due in no small part to the fact
                  that it has to do a good deal more than the above example does,
                  including some options that require a bit of processing on the input).
                  >
                  POSIX systems that support the thread-safety option have to lock the
                  I/O streams every time you call getc() or putc(). On such systems,
                  getc_unlocked() and putc_unlocked() (POSIX options, not Standard C)
                  will usually be notably faster. Some implementations also provide
                  other means for using the "unlocked" versions.
                  >
                  Other common techniques would be to read in larger blocks at a time,
                  or perhaps to avoid the Standard C buffered I/O calls and use POSIX
                  read(), write() (it's unclear to me how much better that is than to
                  use setvbuf() to turn off buffering and use fwrite() and fread(),
                  which is a good option if you'd like to stick to Standard C).
                  >
                  Taking a look at the source code for GNU cat and other similar
                  utilities like dd, for (Unix-specific) ideas on how to improve
                  efficiency.
                  >
                  --
                  HTH,
                  Micah J. Cowan
                  Programmer, musician, typesetting enthusiast, gamer...http://micah.cowan.name/
                  Thanks!

                  Comment

                  • regis

                    #10
                    Re: Braces or not [Re: cat]

                    Micah Cowan wrote:
                    Richard Heathfield <rjh@see.sig.in validwrites:
                    >
                    >
                    >>>If that's what you mean, then my answer is:
                    >> - It's not appreciably harder to add braces later than it is to put
                    >> them in in the first place.
                    >>
                    >>Agreed. BUT - it is appreciably harder to remember to add them later on
                    >>special occasions than to put them in every time as a matter of habit.
                    >
                    >
                    Hm. I haven't found it to be so.
                    >
                    while (c)
                    c=do_it(c);
                    c=do_another_th ing(c);
                    >
                    looks too broken right away for me not to notice it (though, perhaps
                    now that I'm doing more Python coding work these days, that may
                    change?).

                    while (c);
                    c= do_it(c);

                    the error above is harder to find than:

                    while (c);{
                    c= do_it(c);
                    }

                    you cannot miss the ';' between ')' and '{':
                    it is not a natural location for it, and in fact,
                    for this very reason, you'll rarely find such a code.

                    But the first mistake is often found in the code of
                    my students. And when they ask why their code does not work
                    as expected, you may have a hard time before catching
                    the extra semi-colon.

                    Comment

                    • Charlton Wilbur

                      #11
                      Re: Braces or not [Re: cat]

                      >>>>"r" == regis <regis@dil.un iv-mrs.frwrites:

                      rwhile (c); c= do_it(c);

                      rthe error above is harder to find than:

                      rwhile (c);{ c= do_it(c); }

                      rBut the first mistake is often found in the code of my
                      rstudents. And when they ask why their code does not work as
                      rexpected, you may have a hard time before catching the extra
                      rsemi-colon.

                      And then, after a semester where they've made this mistake a
                      half-dozen times, either they start recognizing the symptoms of that
                      mistake, they have learned to single-step through suspicious code in a
                      debugger, or they need to switch majors to something less
                      intellectually taxing.

                      Charlton



                      --
                      Charlton Wilbur
                      cwilbur@chromat ico.net

                      Comment

                      • SM Ryan

                        #12
                        Re: cat

                        Jag <talon.jag@gmai l.comwrote:
                        # I've read parts of K&R's ANSI C v2 and this is what their cat looked
                        # like but when I compared the speed of this code to gnu cat, it seems
                        # very slow. How do I optimize this for greater speeds? is there an
                        # alternative algorithm?

                        The system cat exploits features of the specific system that
                        are not available in ANSI C. For example on unix, you can
                        avoid stdio altogether, and do something like
                        read -shared buffer -write

                        You can also use asynchronous I/O and multiple buffers to
                        have overlapping reads and writes.

                        But all this is system specific.

                        --
                        SM Ryan http://www.rawbw.com/~wyrmwif/
                        If you plan to shoplift, let us know.
                        Thanks

                        Comment

                        • user923005

                          #13
                          Re: cat

                          On Mar 5, 6:06 pm, Jag <talon....@gmai l.comwrote:
                          I've read parts of K&R's ANSI C v2 and this is what their cat looked
                          like but when I compared the speed of this code to gnu cat, it seems
                          very slow. How do I optimize this for greater speeds? is there an
                          alternative algorithm?
                          >
                          void catfile(FILE *in, FILE *out) {
                              register int num_char;
                          >
                              /*Get characters*/
                              while ((num_char = getc(in)) != EOF) {
                                  /*Print to standard output*/
                                  putc(num_char, out);
                              }
                          >
                          }
                          C:\tmp>dir dict.sql
                          Volume in drive C has no label.
                          Volume Serial Number is 0890-87CA

                          Directory of C:\tmp

                          03/01/2007 11:48 AM 7,127,408 dict.sql
                          1 File(s) 7,127,408 bytes
                          0 Dir(s) 5,202,309,120 bytes free

                          C:\tmp>cat dict.sql dict.out
                          standard cat took 1.984000 seconds
                          big buffer cat took 0.000000 seconds

                          C:\tmp>type cat.c
                          #include <stdio.h>
                          #include <stdlib.h>
                          #include <time.h>
                          void catfilebuffer(F ILE * in, FILE * out)
                          {
                          register int num_char;

                          setvbuf(in, NULL, _IOFBF, 1024 * 16);
                          setvbuf(out, NULL, _IOFBF, 1024 * 16);

                          /* Get characters */
                          while ((num_char = getc(in)) != EOF) {
                          /* Print to standard output */
                          putc(num_char, out);
                          }
                          }

                          void catfilenobuff(F ILE * in, FILE * out)
                          {
                          register int num_char;

                          /* Get characters */
                          while ((num_char = getc(in)) != EOF) {
                          /* Print to standard output */
                          putc(num_char, out);
                          }
                          }

                          int main(int argc, char **argv)
                          {
                          FILE *in = stdin;
                          FILE *out = stdout;
                          clock_t start,
                          end;
                          static const double cps = 1.0 / CLOCKS_PER_SEC;
                          if (argc 1) {
                          in = fopen(argv[1], "r");
                          if (in == NULL) {
                          printf("Error opening %s\n", argv[1]);
                          exit(EXIT_FAILU RE);
                          }
                          }
                          if (argc 2) {
                          out = fopen(argv[2], "w");
                          if (out == NULL) {
                          printf("Error opening %s\n", argv[2]);
                          exit(EXIT_FAILU RE);
                          }
                          }
                          start = clock();
                          catfilenobuff(i n, out);
                          end = clock();
                          printf("standar d cat took %f seconds\n", (end - start) * cps);
                          start = clock();
                          catfilebuffer(i n, out);
                          end = clock();
                          printf("big buffer cat took %f seconds\n", (end - start) * cps);
                          fflush(NULL);
                          return 0;
                          }

                          Comment

                          • user923005

                            #14
                            Re: cat

                            On Mar 6, 12:30 pm, user923005 <dcor...@connx. comwrote:
                            On Mar 5, 6:06 pm, Jag <talon....@gmai l.comwrote:
                            >
                            I've read parts of K&R's ANSI C v2 and this is what their cat looked
                            like but when I compared the speed of this code to gnu cat, it seems
                            very slow. How do I optimize this for greater speeds? is there an
                            alternative algorithm?
                            >
                            void catfile(FILE *in, FILE *out) {
                                register int num_char;
                            >
                                /*Get characters*/
                                while ((num_char = getc(in)) != EOF) {
                                    /*Print to standard output*/
                                    putc(num_char, out);
                                }
                            >
                            }
                            >
                            C:\tmp>dir dict.sql
                             Volume in drive C has no label.
                             Volume Serial Number is 0890-87CA
                            >
                             Directory of C:\tmp
                            >
                            03/01/2007  11:48 AM         7,127,408 dict.sql
                                           1 File(s)      7,127,408 bytes
                                           0 Dir(s)   5,202,309,120 bytes free
                            >
                            C:\tmp>cat dict.sql dict.out
                            standard cat took 1.984000 seconds
                            big buffer cat took 0.000000 seconds
                            >
                            C:\tmp>type cat.c
                            #include <stdio.h>
                            #include <stdlib.h>
                            #include <time.h>
                            void            catfilebuffer(F ILE * in, FILE * out)
                            {
                                register int    num_char;
                            >
                                setvbuf(in, NULL, _IOFBF, 1024 * 16);
                                setvbuf(out, NULL, _IOFBF, 1024 * 16);
                            >
                                /* Get characters */
                                while ((num_char = getc(in)) != EOF) {
                                    /* Print to standard output */
                                    putc(num_char, out);
                                }
                            >
                            }
                            >
                            void            catfilenobuff(F ILE * in, FILE * out)
                            {
                                register int    num_char;
                            >
                                /* Get characters */
                                while ((num_char = getc(in)) != EOF) {
                                    /* Print to standard output */
                                    putc(num_char, out);
                                }
                            >
                            }
                            >
                            int             main(int argc, char **argv)
                            {
                                FILE           *in = stdin;
                                FILE           *out = stdout;
                                clock_t         start,
                                                end;
                                static const double  cps = 1.0 / CLOCKS_PER_SEC;
                                if (argc 1) {
                                    in = fopen(argv[1], "r");
                                    if (in == NULL) {
                                        printf("Error opening %s\n", argv[1]);
                                        exit(EXIT_FAILU RE);
                                    }
                                }
                                if (argc 2) {
                                    out = fopen(argv[2], "w");
                                    if (out == NULL) {
                                        printf("Error opening %s\n", argv[2]);
                                        exit(EXIT_FAILU RE);
                                    }
                                }
                                start = clock();
                                catfilenobuff(i n, out);
                                end = clock();
                                printf("standar d cat took %f seconds\n", (end - start) * cps);
                                start = clock();
                                catfilebuffer(i n, out);
                                end = clock();
                                printf("big buffer cat took %f seconds\n", (end - start) * cps);
                                fflush(NULL);
                                return 0;
                            >
                            >
                            >
                            }
                            Oops. Forgot to rewind. Let me try that again...

                            Comment

                            • user923005

                              #15
                              Re: cat

                              On Mar 6, 12:30 pm, user923005 <dcor...@connx. comwrote:
                              On Mar 5, 6:06 pm, Jag <talon....@gmai l.comwrote:
                              >
                              I've read parts of K&R's ANSI C v2 and this is what their cat looked
                              like but when I compared the speed of this code to gnu cat, it seems
                              very slow. How do I optimize this for greater speeds? is there an
                              alternative algorithm?
                              >
                              void catfile(FILE *in, FILE *out) {
                                  register int num_char;
                              >
                                  /*Get characters*/
                                  while ((num_char = getc(in)) != EOF) {
                                      /*Print to standard output*/
                                      putc(num_char, out);
                                  }
                              >
                              }
                              >
                              C:\tmp>dir dict.sql
                               Volume in drive C has no label.
                               Volume Serial Number is 0890-87CA
                              >
                               Directory of C:\tmp
                              >
                              03/01/2007  11:48 AM         7,127,408 dict.sql
                                             1 File(s)      7,127,408 bytes
                                             0 Dir(s)   5,202,309,120 bytes free
                              >
                              C:\tmp>cat dict.sql dict.out
                              standard cat took 1.984000 seconds
                              big buffer cat took 0.000000 seconds
                              >
                              C:\tmp>type cat.c
                              #include <stdio.h>
                              #include <stdlib.h>
                              #include <time.h>
                              void            catfilebuffer(F ILE * in, FILE * out)
                              {
                                  register int    num_char;
                              >
                                  setvbuf(in, NULL, _IOFBF, 1024 * 16);
                                  setvbuf(out, NULL, _IOFBF, 1024 * 16);
                              >
                                  /* Get characters */
                                  while ((num_char = getc(in)) != EOF) {
                                      /* Print to standard output */
                                      putc(num_char, out);
                                  }
                              >
                              }
                              >
                              void            catfilenobuff(F ILE * in, FILE * out)
                              {
                                  register int    num_char;
                              >
                                  /* Get characters */
                                  while ((num_char = getc(in)) != EOF) {
                                      /* Print to standard output */
                                      putc(num_char, out);
                                  }
                              >
                              }
                              >
                              int             main(int argc, char **argv)
                              {
                                  FILE           *in = stdin;
                                  FILE           *out = stdout;
                                  clock_t         start,
                                                  end;
                                  static const double  cps = 1.0 / CLOCKS_PER_SEC;
                                  if (argc 1) {
                                      in = fopen(argv[1], "r");
                                      if (in == NULL) {
                                          printf("Error opening %s\n", argv[1]);
                                          exit(EXIT_FAILU RE);
                                      }
                                  }
                                  if (argc 2) {
                                      out = fopen(argv[2], "w");
                                      if (out == NULL) {
                                          printf("Error opening %s\n", argv[2]);
                                          exit(EXIT_FAILU RE);
                                      }
                                  }
                                  start = clock();
                                  catfilenobuff(i n, out);
                                  end = clock();
                                  printf("standar d cat took %f seconds\n", (end - start) * cps);
                                  start = clock();
                                  catfilebuffer(i n, out);
                                  end = clock();
                                  printf("big buffer cat took %f seconds\n", (end - start) * cps);
                                  fflush(NULL);
                                  return 0;
                              >
                              >
                              >
                              }- Hide quoted text -
                              >
                              - Show quoted text -

                              #include <stdio.h>
                              #include <stdlib.h>
                              #include <time.h>
                              void catfilebuffer(F ILE * in, FILE * out)
                              {
                              register int num_char;

                              setvbuf(in, NULL, _IOFBF, 1024 * 16);
                              setvbuf(out, NULL, _IOFBF, 1024 * 16);

                              /* Get characters */
                              while ((num_char = getc(in)) != EOF) {
                              /* Print to standard output */
                              putc(num_char, out);
                              }
                              }

                              void catfilenobuff(F ILE * in, FILE * out)
                              {
                              register int num_char;

                              /* Get characters */
                              while ((num_char = getc(in)) != EOF) {
                              /* Print to standard output */
                              putc(num_char, out);
                              }
                              }

                              int main(int argc, char **argv)
                              {
                              FILE *in = stdin;
                              FILE *out = stdout;
                              clock_t start,
                              end;
                              static const double cps = 1.0 / CLOCKS_PER_SEC;
                              if (argc 1) {
                              in = fopen(argv[1], "r");
                              if (in == NULL) {
                              printf("Error opening %s\n", argv[1]);
                              exit(EXIT_FAILU RE);
                              }
                              }
                              if (argc 2) {
                              out = fopen(argv[2], "w");
                              if (out == NULL) {
                              printf("Error opening %s\n", argv[2]);
                              exit(EXIT_FAILU RE);
                              }
                              }
                              start = clock();
                              catfilenobuff(i n, out);
                              end = clock();
                              printf("standar d cat took %f seconds\n", (end - start) * cps);
                              rewind(in);
                              fclose(out);
                              if (argc 2) {
                              out = fopen(argv[2], "w");
                              if (out == NULL) {
                              printf("Error opening %s\n", argv[2]);
                              exit(EXIT_FAILU RE);
                              }
                              } else
                              out = stdout;
                              start = clock();
                              catfilebuffer(i n, out);
                              end = clock();
                              printf("big buffer cat took %f seconds\n", (end - start) * cps);
                              fflush(NULL);
                              return 0;
                              }
                              /*
                              Not nearly so dramatic! ;-)
                              C:\tmp>cat dict.sql dict.out
                              standard cat took 1.968000 seconds
                              big buffer cat took 1.891000 seconds
                              */

                              Comment

                              Working...