[gnu.utils.bug] GNU DIFF speedup: don't flush stdout after diffing each file

eggert@twinsun.com (Paul Eggert) (10/25/89)

GNU DIFF version 1.10 flushes stdout after diffing each file.  This causes
'diff -r' to issue many more 'write' system calls than it has to, and also
causes most writes to be misaligned with respect to the file system.  Here is a
patch that causes stdout to be flushed only before error messages.  (The patch
also changes fatal() to match its comment.)

When diffing the source of GCC 1.35 vs GCC 1.36 on a Sparcstation 1 running
SunOS 4.0.3c, these patches decrease the number of 'write' system calls by 42%,
and improve wall clock speed by about 7%.


*** old/diff.c	Tue Oct 24 21:55:02 1989
--- new/diff.c	Tue Oct 24 21:52:37 1989
***************
*** 590,597 ****
      message ("Files %s and %s are identical\n",
  	     inf[0].name, inf[1].name);
  
-   fflush (stdout);
- 
    if (dir0 != 0)
      free (inf[0].name);
    if (dir1 != 0)
--- 590,595 ----




*** old/util.c	Tue Oct 24 21:55:03 1989
--- new/util.c	Tue Oct 24 21:52:39 1989
***************
*** 26,33 ****
--- 26,35 ----
  perror_with_name (text)
       char *text;
  {
+   print_message_queue ();
    fprintf (stderr, "%s: ", program);
    perror (text);
+   fflush (stderr);
  }
  
  /* Use when a system call returns non-zero status and that is fatal.  */
***************
*** 36,44 ****
  pfatal_with_name (text)
       char *text;
  {
!   print_message_queue ();
!   fprintf (stderr, "%s: ", program);
!   perror (text);
    exit (2);
  }
  
--- 38,44 ----
  pfatal_with_name (text)
       char *text;
  {
!   perror_with_name (text);
    exit (2);
  }
  
***************
*** 51,69 ****
       char *arg;
       char *arg1;
  {
    fprintf (stderr, "%s: ", program);
    fprintf (stderr, format, arg, arg1);
    fprintf (stderr, "\n");
  }
  
  /* Print an error message containing the string TEXT, then exit.  */
  
  void
! fatal (message)
!      char *message;
  {
    print_message_queue ();
!   error (message, "");
    exit (2);
  }
  
--- 51,71 ----
       char *arg;
       char *arg1;
  {
+   fflush (stdout);
    fprintf (stderr, "%s: ", program);
    fprintf (stderr, format, arg, arg1);
    fprintf (stderr, "\n");
+   fflush (stderr);
  }
  
  /* Print an error message containing the string TEXT, then exit.  */
  
  void
! fatal (text)
!      char *text;
  {
    print_message_queue ();
!   error ("%s", text);
    exit (2);
  }
  
***************
*** 102,107 ****
--- 104,110 ----
  
    for (m = msg_chain; m; m = m->next)
      printf (m->format, m->arg1, m->arg2);
+   fflush (stdout);
  }
  
  /* Call before outputting the results of comparing files NAME0 and NAME1