m4-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

03-esyscmd-pipe-buffer-8


From: Dave
Subject: 03-esyscmd-pipe-buffer-8
Date: Sat, 16 Mar 2002 16:07:40 +0100

Hi.

Reading from pipe more than one byte at a time is faster.
Optimal buffer size seems to be 8. Speed improvement is 12%.

I will send detailed testing log later.

ChangeLog:
2002-03-16  David Sterba  <address@hidden>

        * modules/gnu.c (esyscmd): Read from pipe per 8 bytes, speeds up
        esyscmd by 12%.

Patch:
diff -urN -X .diffignore m4.inc/modules/gnu.c m4/modules/gnu.c
--- m4.inc/modules/gnu.c        Sat Oct 13 10:54:53 2001
+++ m4/modules/gnu.c    Fri Mar  8 19:53:17 2002
@@ -498,7 +498,8 @@
 M4BUILTIN_HANDLER (esyscmd)
 {
   FILE *pin;
-  int ch;
+  int rd;
+  char write_buf[8];          /* 8 seems to be optimal size for buffer */
 
   m4_debug_flush_files ();
   pin = popen (M4ARG (1), "r");
@@ -510,8 +511,10 @@
     }
   else
     {
-      while ((ch = getc (pin)) != EOF)
-        obstack_1grow (obs, (char) ch);
+      while ( (rd = fread (write_buf, 1, 8, pin)) == 8)
+        obstack_grow (obs, write_buf, 8);
+      if (rd > 0)
+        obstack_grow (obs, write_buf, rd);
       m4_sysval = pclose (pin);
     }
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]